470,848 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

XmlSerializer: Dealing with an evolving class

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")
End If

If version = 2 Then
Me.PropertyA = info.GetInt32("PropertyA")
End If

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,
Joel Moore
Jun 21 '06 #1
0 1078

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Chris Aitchison | last post: by
3 posts views Thread by Anthony Bouch | last post: by
2 posts views Thread by magister | last post: by
4 posts views Thread by Steve Long | last post: by
3 posts views Thread by Wayne | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.