我有一個類Foo標記爲[Serializable]
並執行ISerializable
。我試圖通過DataContractSerializer序列化它。在GetObjectData使用我這樣做:錯誤:「反序列化程序不知道映射到此合同的任何類型」?
info.AddValue("Test", new[] { 1,2,3});
它失敗:
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.
我想傳遞一個knownTypes
ARG到DataContractSerializer的構造 - 沒有幫助。