[Mono-bugs] [Bug 582732] New: DataSet method WriteXml fails when DataColumn has extended properties and MaxLength property is set. ReadXml does not read extended properties also.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Feb 24 10:13:05 EST 2010


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

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


           Summary: DataSet method WriteXml fails when DataColumn has
                    extended properties and MaxLength property is set.
                    ReadXml does not read extended properties also.
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Critical
          Priority: P5 - None
         Component: Sys.Data
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: kuritsu at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=344481)
 --> (http://bugzilla.novell.com/attachment.cgi?id=344481)
Test Case which shows the bug.

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; es-MX; rv:1.9.1.5)
Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5

I have a DataSet with a DataTable and several extended properties set in one or
two DataColumn. The MaxLength properties of these DataColumn are also set. When
I call the WriteXml method of the DataSet with a file name and
XmlWriteMode.WriteSchema, the following exception comes out:

This XmlWriter does not accept EndDocument at this state Error.
  at System.Xml.XmlTextWriter.WriteEndDocument () [0x00020] in
/home/jeff/Installers/mono-2.6.1/Mono/mono-2.6.1/mcs/class/System.XML/System.Xml/XmlTextWriter2.cs:520 
  at System.Data.DataSet.WriteXml (System.String fileName, XmlWriteMode mode)
[0x00023] in
/home/jeff/Installers/mono-2.6.1/Mono/mono-2.6.1/mcs/class/System.Data/System.Data/DataSet.cs:726 
  at Bugs.XmlSchemaWriterBug.MainClass.Main (System.String[] args) [0x0010c] in
/home/jeff/Projects/Bugs/Bugs.XmlSchemaWriterBug/Main.cs:25 

Also, when I call the ReadXml with a file name and XmlReadMode.ReadSchema, and
the XML contains information of extended properties, the ExtendedProperties
property of the DataSet, DataTable or DataColumn is not filled with such info.



Reproducible: Always

Steps to Reproduce:
1. Create a C# console application project in MonoDevelop.
2. Add System.Data as reference.
3. In usings section, add System.Collections and System.Data.
4. In the Main method of the main class, put the following code:

DataSet dataSet = new DataSet();
dataSet.ExtendedProperties.Add("DS1", "extended0");
DataTable table = new DataTable("TABLE1");
table.ExtendedProperties.Add("T1", "extended1");
table.Columns.Add("C1", typeof(int));
table.Columns[0].MaxLength = 10;
table.Columns.Add("C2", typeof(string));
table.Columns[0].MaxLength = 20;
table.Columns[0].ExtendedProperties.Add("C1Ext2", "extended2");
table.Columns[1].ExtendedProperties.Add("C2Ext3", "extended3");
dataSet.Tables.Add(table);
table.LoadDataRow(new object[]{1, "One"}, false);
table.LoadDataRow(new object[]{2, "Two"}, false);
try
{
    dataSet.WriteXml("test.xml", XmlWriteMode.WriteSchema);
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
    Console.WriteLine(ex.StackTrace);
}
dataSet = new DataSet();
// Does not read extended properties
dataSet.ReadXml("test2.xml", XmlReadMode.ReadSchema);
Console.WriteLine("DataSet extended properties:");
foreach (DictionaryEntry p in dataSet.ExtendedProperties)
{
    Console.WriteLine (String.Format("{0} = {1}", p.Key, p.Value));
}
Console.WriteLine("DataTable extended properties:");
foreach (DictionaryEntry p in dataSet.Tables[0].ExtendedProperties)
{
    Console.WriteLine (String.Format("{0} = {1}", p.Key, p.Value));
}
Console.WriteLine("DataColumn 0 extended properties:");
foreach (DictionaryEntry p in dataSet.Tables[0].Columns[0].ExtendedProperties)
{
    Console.WriteLine (String.Format("{0} = {1}", p.Key, p.Value));
}
Console.WriteLine("DataColumn 1 extended properties:");
foreach (DictionaryEntry p in dataSet.Tables[0].Columns[1].ExtendedProperties)
{
    Console.WriteLine (String.Format("{0} = {1}", p.Key, p.Value));
}
Console.ReadLine();

5. Create an XML file like the following (name it test2.xml) to try to read
extended properties:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
    <xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true" msprop:DS1="extended0">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="TABLE1" msprop:T1="extended1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="C1" type="xs:int" minOccurs="0"
msprop:C1Ext2="extended2" />
                <xs:element name="C2" type="xs:string" minOccurs="0"
msprop:C2Ext3="extended3" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <TABLE1>
    <C1>1</C1>
    <C2>One</C2>
  </TABLE1>
  <TABLE1>
    <C1>2</C1>
    <C2>Two</C2>
  </TABLE1>
</NewDataSet>

6. Run and check the results.
Actual Results:  
This is what is written on the console: 

This XmlWriter does not accept EndDocument at this state Error.
  at System.Xml.XmlTextWriter.WriteEndDocument () [0x00020] in
/home/jeff/Installers/mono-2.6.1/Mono/mono-2.6.1/mcs/class/System.XML/System.Xml/XmlTextWriter2.cs:520 
  at System.Data.DataSet.WriteXml (System.String fileName, XmlWriteMode mode)
[0x00023] in
/home/jeff/Installers/mono-2.6.1/Mono/mono-2.6.1/mcs/class/System.Data/System.Data/DataSet.cs:726 
  at Bugs.XmlSchemaWriterBug.MainClass.Main (System.String[] args) [0x00121] in
/home/jeff/Projects/Bugs/Bugs.XmlSchemaWriterBug/Main.cs:26 
DataSet extended properties:
DataTable extended properties:
DataColumn 0 extended properties:
DataColumn 1 extended properties:

As you can see, an Exception is written by the catch block when calling
WriteXml, and after you call ReadXml, no extended properties info is written on
the console. 

Expected Results:  
The console should show this:

DataSet extended properties:
DS1 = extended0
DataTable extended properties:
T1 = extended1
DataColumn 0 extended properties:
C1Ext2 = extended2
DataColumn 1 extended properties:
C2Ext3 = extended3

Notice how the extended properties info is output. Also, the test.xml file
should look like this:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
    <xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true" msprop:DS1="extended0">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="TABLE1" msprop:T1="extended1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="C1" minOccurs="0" msprop:C1Ext2="extended2">
                  <xs:simpleType>
                    <xs:restriction base="xs:int">
                      <xs:maxLength value="20" />
                    </xs:restriction>
                  </xs:simpleType>
                </xs:element>
                <xs:element name="C2" type="xs:string" minOccurs="0"
msprop:C2Ext3="extended3" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <TABLE1>
    <C1>1</C1>
    <C2>One</C2>
  </TABLE1>
  <TABLE1>
    <C1>2</C1>
    <C2>Two</C2>
  </TABLE1>
</NewDataSet>

Notice that extended properties and MaxLength info are saved.

-- 
Configure bugmail: http://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