Error: "The deserializer has no knowledge of any type that maps to this contract"?
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' d开发者_StackOverflow社区ata 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.
Passing a knownTypes
arg to the DataContractSerializer constructor will not help. Instead, add [KnownType(typeof(int[]))]
to class Foo itself.
精彩评论