Versioning and Serialization

M

Mike

I'm having a problem with serializing between different versions of classes.
I've read the many posts on handling versioning by implementing
ISerializable but unforunately we shipped the first few versions of our app
thinking we had done that, but unforunately we hadn't. Thus all the
original serialized object were done using pretty much standard .NET binary
serialization.

We're using the binary formatter and now have a number of typed collections
that were serialized using the original format and now a number using the
newer format based on ISerializable. We can't just ignore the old versions
and need some way to convert them. I tried following the articles the
talked about the SerializationBinder under the assumption that I could at
runtime decide which version of an assembly (old or new) should handle the
deserizliation but it seemed to ignore anything I did and still failed.

So some questions;

1) If I ship the old version of the assembly that created the serialized
object, Acme.App.Legacy.dll and the new Acme.app.dl can I at deserialization
time decide which version of the assemby should handle the deserialization?
If so, what about other assemblies that are reference by those assemblies?

2) Is the serialization binder supposed to support what I'm trying to do?

3) If I can't do that does anyone have any suggestions on how to convert
those old serialized objects?

Thanks,

Mike
 
D

Dave L

I have this same issue as well. The basic problem with the binder is that at
some point you need to know what version of the class being deserialized.
For that, you need to serialize a version class. Each time you change the
file format, update the version. Maybe it has a 32-bit integer version
number.

Your implemenation options could be:

1) When saving your file, serialize the version class first, then append the
serialized file you're really trying to save. Upon reading, read the version
serialized class first, find out the file version, then setup your binders
for the upconversion and read the second class for disk. This way, you have
1 binded class per version you want to upgrade.

2) Each class your saving inherits from the version base class, and when the
binder class is called, extract the version so you know how to perform the
upconversion.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top