I have this classes:
[DataContract]
class ClassA
{
[DataMember]
public Object Value; // and this can be of ClassB or some primitive type.
...
}
[DataContract]
class ClassB : IEnumerable<KeyValuePair<String, ClassA>>
{
[DataMember]
private Dictionary<String, ClassA> dictionary;
...
}
but getting this exception when serialization take place:
Type 'MyNamespace.ClassA' with data contract name 'ClassA:http://schemas.datacontract.org/2004/07/MyNamespace' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
I feel that I should use KnownType
attribute, but I can't figure out how, because I am not owning IEnumerable<T>
.
Can anyone help? Thanks.
[KnownType(typeof(int))]
help when?System.Int32
is always a known type. – Breastsummer