Hello,
I'm storing user settings in the database, according to E968. But when using MySql as database an error occurs when the settings are loaded.
One can reproduce this with E968: configure it to use a MySql database, log in as user Configurator, log off and log in again:
The error occurred:
Type: XmlException
Message: Data at the root level is invalid. Line 1, position 1.
Data: 0 entries
Stack trace:
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at DevExpress.Utils.Serializing.XmlXtraSerializer.DeserializeCore(Stream stream, String appName, IList objects)
at DevExpress.Utils.Serializing.XtraSerializer.DeserializeObject(Object obj, Stream stream, String appName, OptionsLayoutBase options)
at DevExpress.Utils.Serializing.XtraSerializer.DeserializeObject(Object obj, Stream stream, String appName)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at DevExpress.XtraEditors.XtraForm.WndProc(Message& msg)
at DevExpress.ExpressApp.Win.Templates.XtraFormTemplateBase.WndProc(Message& msg)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
How can this be fixed?
Olaf
Hi Olaf.
I have tried to reproduce this exception based on the instruction you provided, but to no avail. Please verify that the property containing the serialized model (XPUserSettingsAspect.Xml) was decorated with the [Size(SizeAttribute.Unlimited)] attribute before the database was created, and the corresponding database column type allows storing strings of an unlimited size.
Hi Michael,
I retried this with InMemoryDataStore, MSAccess, SQLServer and MySql. Only with MySql I'm getting this error. Maybe this is related to out MySql instance configuration - but I cannot see any reason for this. I compared the values for column xml from each database to each other - no differences.
Can you please help me find out how to debug this issue? The call stack inplies that the XmlXtraSerializer tries to deserialize something on the main form (maybe the DockManagerSettings?), but I don't know how to find deeper information, for example what XML-string is causing the exception.
Olaf
The call stack you provided only shows that XML data the serializer tries to read was corrupted. Please check that data stored in the database is correct. For example, set a breakpoint in the overridden OnLoaded method of the XPUserSettingsAspect class and check the value of the Xml property in the debugger. If this does not help, please provide us with the dump of your database, so we can replicate the situation locally.
Hi Michael,
I spend the last two days checking the xml data …
I finally found what's the issue:
- the DockManager saves its settings in the model as xml with a BOM : ?<XtraSerializer …
- this BOM displayed as "?" in the VS debugger is the unicode char EF BB BF
- when this xml is loaded from the MySql-db the value has changed to a real question mark "?"
- this question mark is the "invalid data at the root level Line 1, position 1
About my database:
- XPO has created it with all tables/columns
- the column xpusersettingsaspect.Xml is of type longtext
- the connectionstring "XpoProvider=MySql;server=server2;user id=usr; password=pwd; database=E968;persist security info=true;CharSet=utf8;" contains the utf8 hint
- database variables:
character_set_client utf8
character_set_connection utf8
character_set_database latin1
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
collation_connection utf8_general_ci
collation_database latin1_swedish_ci
collation_server latin1_swedish_ci
Can you please check that your test targets the mysql database? In the "Sub Main" the connection string is changed to InMemoryDataStoreProvider when running in debug mode:
#If DEBUG Then
DevExpress.ExpressApp.Xpo.InMemoryDataStoreProvider.Register()
winApplication.ConnectionString = DevExpress.ExpressApp.Xpo.InMemoryDataStoreProvider.ConnectionString
#End If
(I think you changed it)
What do I have to chage to get the utf-8 xml properly stored?
Olaf
Thank you for the additional information. Yes, I have tested this example with the MySQL database and the serialized model data does not contain BOM on my side. It seems that your database does not use Unicode for string columns:
- your character_set_database and character_set_server variables are set to "latin1". They are set to "utf8" on my side.
- your collation_database and collation_server variables are set to "latin1_swedish_ci". They are set to "utf8_general_ci" on my side.