Backward compatibility vs serialization

G

Guest

Hi,

Serialization is great!. No doubt. However, as my program develope I often
have to restart with new data as the serialized classes changes in fields.

Is there a clever way to implement backward compatibility using
serialization. Just as youre able to open old word documents in the latest
release of the program.

Best regards Jesper.
 
N

Nicholas Paldino [.NET/C# MVP]

Jesper,

You have three options here. The first is to use custom serialization,
and then set some sort of a flag in the data which indicates what version it
is, and then have your code work accordingly.

The second is to use the OptionalField attribute on all new fields on
your object after the first version is released. Of course, this limits the
serialization options of your object severely.

The last is to use the DataContractSerializer and the Data Contract
model. In this model, you have to opt-in (specifying which fields you want
to serialize) and there is an easier mechanism for tolerating information in
the serialization stream that doesn't exist.
 

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