Ticket Q497453
Visible to All Users

XmlException (Data at the root level is invalid. Line 1, position 1.) when storing Xml data (e.g., Application Model differences with ModelDifferenceDbStore, workflow activities) in MySql without UTF8 encoding for string columns

created 12 years ago

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

Show previous comments (2)
DevExpress Support Team 12 years ago

    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

      DevExpress Support Team 12 years ago

        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.

        Answers approved by DevExpress Support

        created 9 years ago

        To avoid this behavior, make sure your MySql database is configured to use Unicode for string columns:

        1. your character_set_database and character_set_server variables are set to "utf8"
        2. your collation_database and collation_server variables are set to  "utf8_general_ci"
          Comments (1)

            Thx! Dennis

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.