I have a few classes to serialize, and deserialize, those classes implement an interface and thats all I really know at runtime about them.
The serialized xml is stored in a database and then, at some point I will need to deserialize this xml into a valid type.
I was thinking of using XmlSerializer , but the constructor requires that I know the type of the data to deserailize. I have this info available when serializing, however, not there when deserializing
So far I can think of a few options, but tbh they dont seem optimal, there must be a better way?
- Store the type, as well as the xml. Do Type.GetType(AssemblyQualifiedName_xmlType)
- Store the type within the xml. Use a base class that contains the type, this is a solution that I particularly dont like because is very invasive.
- try to use this constructor, http://msdn.microsoft.com/en-us/library/7dhb8wb8.aspx I havent tried this. and I want to know for a fact that I wont resolve to a similar but not the same object that it was serialized from.
I would think this is a solved problem and I m just not seeing an obvious solution. What s the best practice in this scenario?.
Note: I have tried serializing to binary, and that works perfectly, but the requirements of the system are that the classes are stored as xml.
Thanks