[Mono-bugs] [Bug 573502] New: DataContractSerializer incorrectly reporting a bad XML file

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Jan 25 10:40:19 EST 2010


http://bugzilla.novell.com/show_bug.cgi?id=573502

http://bugzilla.novell.com/show_bug.cgi?id=573502#c0


           Summary: DataContractSerializer incorrectly reporting a bad XML
                    file
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: x86-64
        OS/Version: RHEL 5
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: mike at realrunners.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Field Engineer
           Blocker: Yes


Description of Problem:
Using the DataContractSerializer and the XmlDictionaryReader classes to
serialize and deserialize a simple object fails. It works in stable 2.6.1.

Steps to reproduce the problem:
given these classes:

[Serializable]
    public enum DBDriver
    {
        SQLite = 1,
        MySQL = 2,
        Oracle = 3,
        Postgresql = 4,
        SQLServer = 5
    }

[Serializable]
    [DataContract]
    public class DBConnectionInfo : IComparable<DBConnectionInfo>
    {
        [DataMember]
        public long ConnectionId { get; set; }
        [DataMember]
        public string ConnectionName { get; set; }
        [DataMember]
        public DBDriver Driver { get; set; }
        [DataMember]
        public string Host { get; set; }
        [DataMember]
        public int Port { get; set; }
        [DataMember]
        public string Username { get; set; }
        [DataMember]
        public string Password { get; set; }
        [DataMember]
        public string DatabaseName { get; set; }
        [DataMember]
        public string DBFilePath { get; set; }
...
    }

[Serializable]
    [DataContract]
    public class Config
    {
        [DataMember]
        public string DefaultConnectionName {get;set;}
        [DataMember]
        public string RepoConnectionName {get;set;}

        public string TempFolder {get;set;}
        public string ConfigFilePath {get;set;}

        private List<DBConnectionInfo> _DBConnections;
        [DataMember]
        public List<DBConnectionInfo> DBConnections
        {
            get 
            {
                if (_DBConnections == null)                
                    _DBConnections = new List<DBConnectionInfo>();              
                return _DBConnections; 
            }
            private set { _DBConnections = value; }
        }
    }


This code:

                try
                {
                    DataContractSerializer serz = new
DataContractSerializer(typeof(Config));
                    using (FileStream fs = new FileStream(configFilePath,
FileMode.Open))
                    {
                        using (XmlDictionaryReader xmlReader =
                            XmlDictionaryReader.CreateTextReader(fs, new
XmlDictionaryReaderQuotas()))
                        {
                            cfg = (Config)serz.ReadObject(xmlReader);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.Log(LoggerType.Logic, LoggerLevel.WARNING,
                        "An error occurred when loading your config file. " +
ex.Message);
                }



And this XML:
<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/LibRelationalMigration">
  <DBConnections>
    <DBConnectionInfo>
      <ConnectionId>9</ConnectionId>
      <ConnectionName>Alta</ConnectionName>
      <DBFilePath>aws1.testhost.com</DBFilePath>
      <DatabaseName>falx</DatabaseName>
      <Driver>Oracle</Driver>
      <Host>aws1.testhost.com</Host>
      <Password>******</Password>
      <Port>1521</Port>
      <Username>master_b</Username>
    </DBConnectionInfo>
  </DBConnections>
  <DefaultConnectionName>Alta</DefaultConnectionName>
  <RepoConnectionName>Hamconf Repo</RepoConnectionName>
</Config>

You get:

Actual Results:

An error occurred when loading your config file. Deserializing type
'LibRelationalMigration.DBConnectionInfo'. Expecting state 'EndElement'.
Encountered state 'Element' with name 'ConnectionName' with namespace
'http://schemas.datacontract.org/2004/07/LibRelationalMigration'.
Failed Capture: You must first set a Repository connection in the application
settings before using the command line tool.
  at RMCmd.Program.SetupConfig (System.String dbPath) [0x00000]
  at RMCmd.Program.Main (System.String[] args) [0x00000]


Expected Results:

No errors... Correctly deserialize the XML and create instances of the classes

How often does this happen? 

Always

Additional Information:

Mono built from mono-142439.tar.bz2

Kernel:
Linux alta 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:34:28 EST 2008 x86_64 x86_64
x86_64 GNU/Linux

mono -V
Mono JIT compiler version 142439 (tarball Mon Jan 25 09:44:14 EST 2010)
Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC and Parallel Mark)
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list