Bug 23649 - DataContractSerializer generic types's name in not compatible with .Net
Summary: DataContractSerializer generic types's name in not compatible with .Net
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 3.2.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-10-06 11:25 UTC by Ghislain
Modified: 2014-10-06 11:25 UTC (History)
1 user (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Ghislain 2014-10-06 11:25:29 UTC
I have an issue when datacontractserializing dictionaries with mono. The serializer names differently the elements corresponding to dictionaries.
The rule for naming the generic types specified in MSDN is : "By default, the data contract name for a generic type is the name of the type, followed by the string "Of", followed by the data contract names of the generic parameters, followed by a hash computed using the data contract namespaces of the generic parameters."
But mono doesn't add the hash key to the names of the generic parameters. 

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,

Note You need to log in before you can comment on or make changes to this bug.