[Mono-list] DataContractSerializer differs from .Net on Generic class

Cocai simionato.cristiano at gmail.com
Thu Jun 16 12:38:09 EDT 2011


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.


More information about the Mono-list mailing list