Which one handles the version better? XmlSerializer and DataContractSerializer?

You need to serialize the object, and it is possible that the version of the assembly changed during deserialization. In addition, it may happen that the object changes slightly.

XmlSerializer does not store type information, and if the object changes a little, it just doesn't crash, but XmlSerializer cannot serialize private or internal properties from a superclass that I cannot mark with attributes. So I looked at the DataContractSerializer. It looks like this because the problem with the private / internal properties of the superclass will be solved, all properties should be checked, and I don't need them, but what about the type information? And how does a DataContractSerializer behave if some properties are deleted, renamed, or added?

+4
source share
3 answers

I conducted a test with a DataContractSerializer, and it seems that the DataContractSerializer is very tolerant of object changes, so I will use this approach.

+2
source

This is not marked as a WCF question, but the fact that you are talking about a DataContractSerializer makes me think that you are working in WCF. If so, it might be interesting to look at the IExtensibleDataObject interface.

Cm:

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

and

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

+1
source

You can still use the XmlSerializer for your needs. But you will have to implement custom serialization logic using the IXmlSerializable interface.

0
source

All Articles