views:

10

answers:

1

I have a class Foo marked [Serializable] and implementing ISerializable. I'm trying to serialize it via DataContractSerializer. In GetObjectData I do this:

info.AddValue("Test", new[] { 1,2,3});

It fails with:

Element ':Test' contains data of the 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:ArrayOfint' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfint' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.

I tried passing a knownTypes arg to the DataContractSerializer constructor - didn't help.

A: 

Passing a knownTypes arg to the DataContractSerializer constructor will not help. Instead, add [KnownType(typeof(int[]))] to class Foo itself.

Stefan Monov