I trying to serialize a custom type which holds a dictionary among other members. The types associated with key and value of the dictionary are interfaces which are implemented.
The dictionary looks like
Dictionary<ITypeA, ITypeA>
TypeA implements ITypeA,
SubTypeOfA inherits from TypeA
SubTypeOfB inherits from SubTypeOfA
pseudo code looks something like this:
List<Type> knownTypes = new List<Type>() {
typeof(TypeA),
typeof(SubTypeOfA),
typeof(SubTypeOfB)
};
DataContractSerializer serializer =
new DataContractSerializer(typeof(DataHolder), knownTypes);
using (FileStream fs = new FileStream(completeFilePath, FileMode.Create))
{
serializer.WriteObject(fs, templateData);
success = true;
}
I get a StackOverflowException when WriteObject() is getting called, am clueless on what is causing that to happen.
All the classes in the hierarchy are decorated with [DataContract] and the members to be serialized are decoreated with [DataMember].
Any help would be appreciated.
DataHolder? What istemplateData? And what do the other types consist of, other than their inheritance?StackOverflowException? Does it give you any clues as to what went wrong?