I\'m trying to use the XmlSerializer to persist a List(T) where T is an interface. The serializer does not like interfaces. I\'m curious if there is a simple way to serializ
Do you have to use XmlSerializer
? This is a known issue with XmlSerializer
.
You can use BinaryFormatter to save to a stream:
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, animals);
Other alternative is to use WCF's DataContractSerializer
and provide types using KnownType attribute.