[Mono-list] DataContractSerializer differs from .Net on Generic class
Atsushi Eno
atsushieno at veritas-vos-liberabit.com
Thu Jun 16 20:13:39 EDT 2011
Haven't exactly examined your repro, but it is likely that .NET adds cryptic
suffix to mapped xml name for generic types, to avoid possible conflicts.
We can add similar suffix but that cannot be compatible with .NET.
In that case, giving explicit data contract name for generic types is a
solution.
Atsushi Eno
(2011/06/17 1:38), Cocai wrote:
> The serialization of a generic class by DataContractSerializer of a generic
> class get different result if it was made in Mono 2.10.2 or in .Net 4, so
> they are not interoperable.
>
> I have tried with:
> [DataContract]
> public class MyClass
> {
> [DataMember]
> public int Age { get; set; }
> }
>
>
> [DataContract]
> [KnownType(typeof(MyClass))]
> [KnownType(typeof(String))]
> public class MyGenerics<T>
> {
> [DataMember]
> public T Test { get; set; }
> }
>
> and serialize :
> var test1 = new MyGenerics<string>() {Test = "test"};
> var test2 = new MyGenerics<MyClass>() {Test = new MyClass() {Age = 4}};
>
> using the constructor
> new DataContractSerializer(typeof (MyGenerics<string>), new [] {typeof
> (MyGenerics<string>)}, int.MaxValue, false, true, null);
>
> or
> new DataContractSerializer(typeof (MyGenerics<MyClass>), new [] {typeof
> (MyGenerics<MyClass>)}, int.MaxValue, false, true, null);
>
> Someone else got the same problem? Has found an easy workaround?
>
> Thanks
> Cristiano
>
> --
> View this message in context: http://mono.1490590.n4.nabble.com/DataContractSerializer-differs-from-Net-on-Generic-class-tp3603011p3603011.html
> Sent from the Mono - General mailing list archive at Nabble.com.
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
>
More information about the Mono-list
mailing list