views:

531

answers:

3

In need to serialize an object and it's possible that the assembly version changed while deserialization. Additionally it can happen, that the object changes a bit.

The XmlSerializer does not store type information and if the object changes a bit, it just does not fail, but the XmlSerializer can not serialize private or internal properties from a super class I can not mark with attributes. So I had a look at the DataContractSerializer. It looks fine so fare, the problem with the private / internal properties of the super class would be solved, all properties have to be marked and I don't need them, but what about the type information? And how does the DataContractSerializer behave, if some properties are removed, renamed or added?

A: 

It is still possible to use XmlSerializer for your needs. But you will have to implement custom serialization logic using IXmlSerializable interface.

Yacoder
+1  A: 

I made a test with the DataContractSerializer and it seems as the DataContractSerializer is very tolerant against object changes, so I'll use the approach.

Enyra
+1  A: 

This isn't marked as a WCF question, but the fact you are talking about DataContractSerializer makes me think that you are working within WCF. If that is the case it might be worhtwhile looking into the IExtensibleDataObject interface.

Refer:

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iextensibledataobject.aspx

and

http://msdn.microsoft.com/en-us/library/ms731138.aspx

Tim Carter