XmlSerializer: Dealing with an evolving class - 06-21-2006 , 04:54 PM
We have an app that currently uses SOAP for a data file format. It works
well enuogh but I would prefer an XML format that's a little friendlier
to the human eye.
I had started looking at converting over to using the XmlSerializer but
quickly ran into a problem. One thing that is nice about the SOAP
formatter's deserialization is that it can easily deal with different
versions of the data file. The class we're serializing includes a
version field and when deserializing we can examine what version file
we're reading and easily deal with missing or changed fields. For
version = info.GetInt32("Version")
If version = 1 Then
Me.PropertyA = info.GetInt32("OldPropertyName")
If version = 2 Then
Me.PropertyA = info.GetInt32("PropertyA")
In other words, SOAP allows you to do something with fields or properties
that have been removed from the class (for whatever reason) but are still
contained in the old versions of the data. The above example is
simplistic and the real situations get more complicated than that but
hopefully you can get the idea.
Anyway, with XmlSerializer the above isn't possible. In the newer
versions of the software those old properties will simply be ignored when
deserializing the file since they aren't part of the class anymore. I
could leave them in the class but that starts to turn the class into a
mess and they will continue to be serialized.
So, is there a serialization mechanism in .NET that works the same as
SOAP (i.e. all available elements loaded into a dictionary of some sort)
but allows me complete control over the output formatting to make it
easier to read?
Thanks for any advice,
|Thread Tools||Search this Thread|