[Mono-list] DataContractSerializer dictionaries element names

gbenrais gbenrais at wakuroo.com
Thu Sep 18 09:28:05 UTC 2014


Hello,
I have an issue when datacontractserializing dictionaries with mono. The
serializer names differently the elements corresponding to dictionaries.
Serialization program

/Dictionary<int, Person> persons = new Dictionary<int, Person>();
persons[1] = new Person("John");
persons[2] = new Person("Bob");
string xml = GetXmlFromData(persons);
persons = GetModelFromXml(xml);
static string GetXmlFromData (object data)
{
  StringWriter sw = new StringWriter ();
  XmlTextWriter xw = new XmlTextWriter (sw);
  DataContractSerializer serializer = new
DataContractSerializer(typeof(Dictionary<int, Person>));
  serializer.WriteObject (xw, data);
  xw.Close ();
  sw.Close ();
  return sw.ToString();
}/
.Net xml

/<ArrayOfKeyValueOfintPerson7l_PWQ7_Pn
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><*KeyValueOfintPerson7l_PWQ7_Pn*><Key>1</Key><Value
xmlns:d3p1="http://schemas.datacontract.org/2004/07/Serialization"><d3p1:_name>John</d3p1:_name></Value></KeyValueOfintPerson7l_PWQ7_Pn><KeyValueOfintPerson7l_PWQ7_Pn><Key>2</Key><Value
xmlns:d3p1="http://schemas.datacontract.org/2004/07/Serialization"><d3p1:_name>Bob</d3p1:_name></Value></KeyValueOfintPerson7l_PWQ7_Pn></ArrayOfKeyValueOfintPerson7l_PWQ7_Pn>/
Mono xml

/<ArrayOfKeyValueOfintPerson
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><*KeyValueOfintPerson*><Key>1</Key><Value><_name
xmlns="http://schemas.datacontract.org/2004/07/Serialization">John</_name></Value></KeyValueOfintPerson><KeyValueOfintPerson><Key>2</Key><Value><_name
xmlns="http://schemas.datacontract.org/2004/07/Serialization">Bob</_name></Value></KeyValueOfintPerson></ArrayOfKeyValueOfintPerson>/

As we can see, we get different names (KeyValueOfintPerson7l_PWQ7_Pn vs
KeyValueOfintPerson). And the program run with mono fails when it reads the
xml from a file output by a program run with .Net.

Thank you for your help,
Ghislain



--
View this message in context: http://mono.1490590.n4.nabble.com/DataContractSerializer-dictionaries-element-names-tp4663929.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list