Bug 242 - DataContractSerializer fails to deserialize List<T> properties
Summary: DataContractSerializer fails to deserialize List<T> properties
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-08-09 11:34 UTC by Brandon Wallace
Modified: 2012-06-06 10:38 UTC (History)
4 users (show)

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


Attachments
VS2010 c# project demonstrating the problem. (3.39 KB, application/x-zip-compressed)
2011-08-09 11:34 UTC, Brandon Wallace
Details


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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Brandon Wallace 2011-08-09 11:34:55 UTC
Created attachment 96 [details]
VS2010 c# project demonstrating the problem.

This is using: Mono JIT compiler version 2.10.3 (tarball Mon Aug  8 13:48:37 CDT 2011).

Attempting to use the DataContractSerializer to deserialize a type with a List<T> property generates the exception below.  This works without error using Microsoft's .NET implementation.  The mono implementation can successfully deserialize IList<T>, IEnumerable<T>, ICollection<T> and T[], but fails on List<T>:


Unhandled Exception: System.InvalidOperationException: Failed to set value of type XmlDataContractDeserializeGenericList.DataItem[] for property System.Collections.Generic.List`1[XmlDataContractDeserializeGenericList.DataItem] DataList ---> System.ArgumentException: failed to convert parameters
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
  at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.SetValue (System.Runtime.Serialization.DataMemberInfo dmi, System.Object obj, System.Object value) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Runtime.Serialization.SerializationMap.SetValue (System.Runtime.Serialization.DataMemberInfo dmi, System.Object obj, System.Object value) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id, Boolean empty) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap (System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Xml.XmlReader reader, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection knownTypes, IDataContractSurrogate surrogate, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver, System.String name, System.String ns, Boolean verifyObjectName) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in <filename unknown>:0
  at XmlDataContractDeserializeGenericList.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Failed to set value of type XmlDataContractDeserializeGenericList.DataItem[] for property System.Collections.Generic.List`1[XmlDataContractDeserializeGenericList.DataItem] DataList ---> System.ArgumentException: failed to convert parameters
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
  at System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
  at System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.SetValue (System.Runtime.Serialization.DataMemberInfo dmi, System.Object obj, System.Object value) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Runtime.Serialization.SerializationMap.SetValue (System.Runtime.Serialization.DataMemberInfo dmi, System.Object obj, System.Object value) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id, Boolean empty) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.DeserializeContent (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer, System.String id) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.SerializationMap.DeserializeObject (System.Xml.XmlReader reader, System.Runtime.Serialization.XmlFormatterDeserializer deserializer) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatterDeserializer.DeserializeByMap (System.Xml.XmlQualifiedName name, System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Type type, System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlFormatterDeserializer.Deserialize (System.Xml.XmlReader reader, System.Type declaredType, System.Runtime.Serialization.KnownTypeCollection knownTypes, IDataContractSurrogate surrogate, System.Runtime.Serialization.DataContractResolver resolver, System.Runtime.Serialization.DataContractResolver defaultResolver, System.String name, System.String ns, Boolean verifyObjectName) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.DataContractSerializer.ReadObject (System.Xml.XmlDictionaryReader reader, Boolean verifyObjectName) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x00000] in <filename unknown>:0
  at XmlDataContractDeserializeGenericList.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0


The example code can be compiled using mono with this command line:

dmcs Program.cs -r:System.Runtime.Serialization

and run with this command line:

mono --runtime=v4.0.30319 ./Program.exe
Comment 1 Gonzalo Paniagua Javier 2012-06-06 10:38:57 UTC
Fixed in https://github.com/mono/mono/commit/691cc77cb712a078fee2b0c76c24d82dde512ccd