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
URL:
Depends on:
Blocks:
 
Reported: 2014-10-06 11:25 UTC by Ghislain
Modified: 2014-10-06 11:25 UTC (History)
1 user (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 23649 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Ghislain 2014-10-06 11:25:29 UTC
Hello,
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,
Ghislain