http://bugzilla.novell.com/show_bug.cgi?id=576520
http://bugzilla.novell.com/show_bug.cgi?id=576520#c0 Summary: DataTable.WriteXml has a wrong behavior when using a column of type "object". Classification: Mono Product: Mono: Class Libraries Version: SVN Platform: All OS/Version: All Status: NEW Severity: Major Priority: P5 - None Component: Sys.Data AssignedTo: [email protected] ReportedBy: [email protected] QAContact: [email protected] Found By: --- Blocker: --- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.78 Safari/532.5 Excepted behavior: When using a column of type "object" in a DataTable, WriteColumnAsElement should check if the object instance implements IXmlSerializable then call the object WriteXml method. Otherwise, an InvalidOperationException must be thrown. Actual behavior: WriteXmlObject is called, leading to a <object>.ToString(). Reproducible: Always Steps to Reproduce: 1. Compile the code in the "Additional Information" section 2. Launch it on MS .NET 3. Launch it with Mono Actual Results: <DocumentElement> <myTable> <classA> <!--OK, WriteXml used--> </classA> <AnObject>ERROR, ToString used</AnObject> <AFloat>3.14</AFloat> <AString>hello</AString> </myTable> <myTable> <classA> <!--OK, WriteXml used--> </classA> <AnObject>ERROR, ToString used</AnObject> <AFloat>6</AFloat> <AString>hello2</AString> </myTable> </DocumentElement> Expected Results: <DocumentElement> <myTable> <classA> <!--OK, WriteXml used--> </classA> <AnObject msdata:InstanceType="MonoBug.A, MonoBug, Version=1.0.0.0, Culture= neutral, PublicKeyToken=null" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata "> <!--OK, WriteXml used--> </AnObject> <AFloat>3.14</AFloat> <AString>hello</AString> </myTable> <myTable> <classA> <!--OK, WriteXml used--> </classA> <AnObject msdata:InstanceType="MonoBug.A, MonoBug, Version=1.0.0.0, Culture= neutral, PublicKeyToken=null" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata "> <!--OK, WriteXml used--> </AnObject> <AFloat>6</AFloat> <AString>hello2</AString> </myTable> </DocumentElement> Sample code: ------------------------------------------------------------------------ using System; using System.Xml.Serialization; using System.Data; namespace MonoBug { public class A : IXmlSerializable { public System.Xml.Schema.XmlSchema GetSchema() { return null; } public void ReadXml(System.Xml.XmlReader reader) { } public void WriteXml(System.Xml.XmlWriter writer) { writer.WriteComment("OK, WriteXml used"); } public override string ToString() { return "ERROR, ToString used"; } } class Program { static void Main(string[] args) { DataTable dt = new DataTable("myTable"); dt.Columns.Add("classA", typeof(A)); dt.Columns.Add("AnObject", typeof(object)); dt.Columns.Add("AFloat", typeof(float)); dt.Columns.Add("AString", typeof(string)); dt.Rows.Add(new object[] { new A(), new A(), 3.14f, "hello" }); dt.Rows.Add(new object[] { new A(), new A(), 6.00f, "hello2" }); dt.WriteXml(Console.Out); Console.ReadLine(); } } } ------------------------------------------------------------------------ Patch: (class/System.Data/System.Data/DataSet.cs diff) ------------------------------------------------------------------------ 1408c1408,1418 < writer.WriteString (WriteObjectXml (rowObject)); --- > if (col.DataType == typeof(object)) { > IXmlSerializable serializableObject = > rowObject as IXmlSerializable; > if (serializableObject == null) > throw new > InvalidOperationException(); > > writer.WriteAttributeString("xmlns", > "msdata", null, "urn:schemas-microsoft-com:xml-msdata"); > > writer.WriteAttributeString("InstanceType", > "urn:schemas-microsoft-com:xml-msdata", > serializableObject.GetType().AssemblyQualifiedName); > serializableObject.WriteXml(writer); > } else { > writer.WriteString (WriteObjectXml > (rowObject)); > } ------------------------------------------------------------------------ -- 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. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
