I'm trying to serialize a dictionary containing non-primitive values. I'm using the normal approach for serializing a dictionary, by implementing IXmlSerializable. Inside the WriteXML method, I convert my non-primitive value to a string (how this converts is not relevant, but that part is working). Inside ReadXML I convert the deserialized value (string) back to the original type.
However, this approach throws an error: InvalidOperationException: To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy.
I assume this is because the value is not primitive. However, it shouldnt need to be serializable as its not serialized (but instead converted to string). Any ideas how to work around this?
Should have mentioned I'm using generics, and the runtime is an Mono environment. The class definition looks like the follwing:
public class SerializableRefDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IXmlSerializable where TValue : NonPrimitiveObject