views:

37

answers:

3

Hello,

We are building application that stores objects to isolated storage using .NET runtime serialization.
Problems occur when we update application by adding some new properties to the classes of objects we are serializing. So we want to do some kind of versioning of the objects in isolated storage so we can check if they are obsolete before they are deserialized.

Any advice and ideas how to do this on best possible way?

What do you think about custom formatter implementing IFormatter interface and can it help instead of vesioning objects?

I wrote about this issue on MS forum more detailed here.

A: 

You COULD have a serialization in the serialization. First a wrapper class telling the version, and holding the inner true class.

This however feels a bit bad smelly..

Marcus Johansson
A: 

Here are a few options (at in any particular order).

  • Name the file based on the version
  • Place the file in a directory based on a version
  • Create a wrapper object that contains metadata about each serialized object such as the version number.
  • Add a property to each object that contains the persisting application's version number
Matthew Whited
A: 

If its binary serialization, you could read the bytes directly, and determine the assembly version from this. Byte number 22 onwards contains information on the assembly and object type, so you could write something that would read this, and then determine if your objects are obsolete.

jasper