[Mono-bugs] [Bug 650388] New: Superfluous ReadEndElement called after calling column IXmlSerializable.ReadXml

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Oct 31 11:10:46 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=650388

https://bugzilla.novell.com/show_bug.cgi?id=650388#c0


           Summary: Superfluous ReadEndElement called after calling column
                    IXmlSerializable.ReadXml
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: x86
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Data
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cvolzke at live.com.au
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1036 Safari/532.5

This line causes a problem:

IXmlSerializable obj = (IXmlSerializable) Activator.CreateInstance
(col.DataType, new object [0]);
if (!reader.IsEmptyElement) {
    obj.ReadXml (reader);
    reader.ReadEndElement ();  // this line shouldn't be there!
} else {

When implementing IXmlSerializable for a column's data type:

void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
{
    reader.ReadStartElement();
    Value = reader.ReadElementString("Value");
    reader.ReadEndElement(); // this line is required when using with an ms.net
DataSet
}


Reproducible: Always

Steps to Reproduce:
1. Set up a DataSet with a column that implements IXmlSerializable
2. Make sure IXmlSerializable.ReadXml is implemented the ms way:
    reader.ReadStartElement();
    Value = reader.ReadElementString("Value");
    reader.ReadEndElement(); // this line is required when using with an ms.net 
3. Call DataSet.ReadXml
Actual Results:  
An exception is thrown, ultimately causing a string to be placed into the row's
column instead of an instance of the IXmlSerializable data type.

Expected Results:  
The IXmlSerializable type should be deserialized correctly.

Test case to reproduce
----------------------

        static string ExpectedXml = @"
<NewDataSet>
  <table>
    <XmlSerializableColumn>
      <Value>Value</Value>
    </XmlSerializableColumn>
    <StringColumn>Value2</StringColumn>
  </table>
</NewDataSet>
".Replace("'", "\"");

        [Test]
        public void Test_ReadXmlSerializable()
        {
            DataSet deserializedDataSet = NewDataSet();
            deserializedDataSet.ReadXml(XmlReader.Create(new
StringReader(ExpectedXml)));
            string deserializedXml = WriteXml(deserializedDataSet);
            Assert.AreEqual(deserializedXml.Trim(), ExpectedXml.Trim());
        }

        static DataSet NewDataSet()
        {
            DataSet data = new DataSet();
            DataTable table = new DataTable("table");
            data.Tables.Add(table);
            table.Columns.Add(new DataColumn("XmlSerializableColumn",
typeof(XmlSerializable)));
            table.Columns.Add(new DataColumn("StringColumn", typeof(string)));
            return data;
        }

        static string WriteXml(DataSet data)
        {
            var writer = new StringWriter();
            var xmlWriter = new XmlTextWriter(writer);
            xmlWriter.Formatting = Formatting.Indented;
            data.WriteXml(xmlWriter);
            return writer.GetStringBuilder().ToString();
        }

        public class XmlSerializable : IXmlSerializable
        {
            public string Value { get; set; }

            public System.Xml.Schema.XmlSchema GetSchema()
            {
                return null;
            }

            public void ReadXml(System.Xml.XmlReader reader)
            {
                reader.ReadStartElement();
                Value = reader.ReadElementString("Value");
                reader.ReadEndElement(); // this line is required when using
with an ms.net DataSet
            }

            public void WriteXml(System.Xml.XmlWriter writer)
            {
                writer.WriteElementString("Value", Value);
            }
        }

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


More information about the mono-bugs mailing list