Serialization missing data

  • Thread starter Thread starter mdb
  • Start date Start date
M

mdb

I have a class (very simple int type data, as shown below) that I have
serialized to disk. In my next version of the program, I have added some
variables to that class. I'm expecting that this will break the
serialization when I try to load the object from disk.

I know there is something in .NET 2.0 to handle this, but how can I do it
with .NET 1.1? Some sample code would be much appreciated...

// The old version
class Data
{
int x;
int y;
}

// The new version
class Data
{
int x;
int y;
int z;
}
 
mdb,

In .NET 1.1, you will have to implement the ISerializable interface, as
well as implement the special serialization constructor. This will allow
you to query the serialization store (passed into the serialization
constructor) to see if a value exists. Then, you can selectively assign
values as you see fit.

Hope this helps.
 
In .NET 1.1, you will have to implement the ISerializable
interface, as
well as implement the special serialization constructor. This will
allow you to query the serialization store (passed into the
serialization constructor) to see if a value exists. Then, you can
selectively assign values as you see fit.

It does help... I guess I would need to explicitly deserialize ALL of the
class members? How would I know the keys to use for GetValue(...), or how
would I know what key belongs to what variable? Are the keys named the
same as the variable name? (Remember that I'm trying to prevent my app
from breaking, and I was using default serialization prior).

I guess this means that I would have manually serialize/deserialize for all
future versions as well?
 
This is similar to another thread ("New versions vs. serialization"),
which might (might not) be of help:

yeah I use the dictionary technique in other code, when I want to save a
configuration and such, but i don't think its that useful here. The
classes that I am serializing are being used for remoting. And while
there's no reason why a dictionary *wouldn't* work in theory, in this case,
i'm trying to make sure that an EXISTING application won't break - not that
the code I'm developing will be extendable in the future. Not only that
but its more of a kludge in this circumstance.

I just wish M$ would release .NET 2.0 already - they've included attributes
to help with this issue.
 
Back
Top