[Mono-list] DataContractSerializer differs from .Net on Generic class
Cocai
simionato.cristiano at gmail.com
Fri Jun 17 05:05:16 EDT 2011
Hi Atsushi,
After some other test I have discovered:
MyGenerics<string> in .Net become i:type=\"b:SpeakerOfstring\" but in Mono
is i:type=\"d3p1:SpeakerOfString\" (note how is written OfString)
I have tried with [DataContract(Name = "MyGenericsOf{0}")] that in .Net
eliminate the random suffix, but in Mono I received this exception by
DataContractSerializer: "System.Argument Exception: localName must be a
valid NCName."; the problem is with "{0}".
Also, If I define the derived class
pubblic class NewMyGenerics : MyGenerics<MyClass>
and adding [KnownType(typeof(NewMyGenerics))] to MyGenerics like this
[DataContract(Name = "MyGenerics")]
[KnownType(typeof(NewMyGenerics))]
public class MyGenerics<T>
DataContractSerializer throw "System.InvalidOperationException: There is
already a registered type for XML name
http://schemas.datacontract.org/2004/07/MyNamespace:MyGenerics"
with stack trace:
at System.Runtime.Serialization.KnownTypeCollection.RegisterContract
(System.Type type) [0x00028] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:857
at System.Runtime.Serialization.KnownTypeCollection.DoTryRegister
(System.Type type) [0x00046] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:687
at System.Runtime.Serialization.KnownTypeCollection.TryRegister
(System.Type type) [0x0000c] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:665
at System.Runtime.Serialization.KnownTypeCollection.RegisterContract
(System.Type type) [0x0006e] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:864
at System.Runtime.Serialization.KnownTypeCollection.DoTryRegister
(System.Type type) [0x00046] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:687
at System.Runtime.Serialization.KnownTypeCollection.TryRegister
(System.Type type) [0x0000c] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:665
at System.Runtime.Serialization.KnownTypeCollection.RegisterContract
(System.Type type) [0x000e8] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:873
at System.Runtime.Serialization.KnownTypeCollection.DoTryRegister
(System.Type type) [0x00046] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:687
at System.Runtime.Serialization.KnownTypeCollection.TryRegister
(System.Type type) [0x0000c] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:665
at System.Runtime.Serialization.KnownTypeCollection.InsertItem (Int32
index, System.Type type) [0x00019] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/KnownTypeCollection.cs:414
at System.Collections.ObjectModel.Collection`1[System.Type].Add
(System.Type item) [0x0000c] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:74
at System.Runtime.Serialization.DataContractSerializer.PopulateTypes
(IEnumerable`1 knownTypes) [0x0002f] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:223
at System.Runtime.Serialization.DataContractSerializer..ctor (System.Type
type, IEnumerable`1 knownTypes) [0x0002f] in
/usr/src/packages/BUILD/mono-2.10.2/mcs/class/System.Runtime.Serialization/System.Runtime.Serialization/DataContractSerializer.cs:74
at System.Runtime.Serialization.DataContractSerializer..ctor (System.Type
type, IEnumerable`1 knownTypes, Int32 maxObjectsInGraph, Boolean
ignoreExtensionDataObject, Boolean preserveObjectReferences,
IDataContractSurrogate dataContractSurrogate) [0x00000] in <filename
unknown>:0
Cristiano
--
View this message in context: http://mono.1490590.n4.nabble.com/DataContractSerializer-differs-from-Net-on-Generic-class-tp3603011p3604913.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list