[Mono-bugs] [Bug 650385] New: IXmlSerializable columns aren't deserialised correctly when writing a diffgram
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sun Oct 31 10:22:31 EDT 2010
https://bugzilla.novell.com/show_bug.cgi?id=650385
https://bugzilla.novell.com/show_bug.cgi?id=650385#c0
Summary: IXmlSerializable columns aren't deserialised correctly
when writing a diffgram
Classification: Mono
Product: Mono: Class Libraries
Version: 2.6.x
Platform: Other
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
When reading IXmlSerializable columns from a diffgram fragment, an exception is
thrown.
Reproducible: Always
Steps to Reproduce:
Read this xml with DataSet.ReadXml:
<diffgr:diffgram xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'
xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1'>
<NewDataSet>
<table diffgr:id='table1' msdata:rowOrder='0' diffgr:hasChanges='inserted'>
<XmlSerializableColumn>
<Value>Value</Value>
</XmlSerializableColumn>
<StringColumn>Value2</StringColumn>
</table>
</NewDataSet>
</diffgr:diffgram>
Actual Results:
An exception is thrown.
Expected Results:
An exception should not thrown, and the xml should be read into the DataSet
property.
Test case to reproduce
----------------------
static string ExpectedXml = @"
<diffgr:diffgram xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'
xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1'>
<NewDataSet>
<table diffgr:id='table1' msdata:rowOrder='0' diffgr:hasChanges='inserted'>
<XmlSerializableColumn>
<Value>Value</Value>
</XmlSerializableColumn>
<StringColumn>Value2</StringColumn>
</table>
</NewDataSet>
</diffgr:diffgram>
".Replace("'", "\"");
[Test]
public void Test_WriteXmlSerializableFromDiffgram()
{
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, XmlWriteMode.DiffGram);
return writer.GetStringBuilder().ToString();
}
public class XmlSerializable : IXmlSerializable
{
public string Value { get; set; }
public x2::System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
reader.ReadStartElement();
Value = reader.ReadElementString("Value");
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("Value", Value);
}
}
Changes that fix the problem (not necessary the best or optimised change)
-------------------------------------------------------------------------
- Add code to the end of DataSet.WriteObjectXml:
IXmlSerializable xmlSerializable = o as IXmlSerializable;
if (xmlSerializable != null)
{
return XmlDataSerializationHelper.ObjectToXmlString(xmlSerializable);
}
- Add code to the end of XmlDataLoader.StringToObject and
XmlDataReader.StringToObject:
if
(typeof(System.Xml.Serialization.IXmlSerializable).IsAssignableFrom(type))
{
return XmlDataSerializationHelper.XmlStringToObject(type, value);
}
- In XmlDiffLoader.LoadColumnChildren, changed "reader.ReadString ()" to:
typeof(System.Xml.Serialization.IXmlSerializable).IsAssignableFrom(Table.Columns[colName].DataType)
? reader.ReadOuterXml() : reader.ReadString()
--
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