Deserialization

U

Urs Vogel

Hi

I'm wondering if there's a technique to deserialize objects which were
serialized with an earlier version of the class. Example:

// version 1
class
{
string myString;
int myInt;
}

is serialized to myobject.xml

In an update version of my app, I need to deserialize the myobject.xml, but
my class has changed due to new app requirements:

// version 2
class
{
string myString;
int myInt;
bool myBool;
}

Now, it won't deserialize anymore. In order to guarantee product update
compatibility, do I have to maintain all previous versions of my serialized
classes in my app and do try-catch-try-catch blocks until the correct
version can be read?

Any hints are appreciated

Urs
 
J

James

Urs Vogel said:
Hi

I'm wondering if there's a technique to deserialize objects which were
serialized with an earlier version of the class. Example:

// version 1
class
{
string myString;
int myInt;
}

is serialized to myobject.xml

In an update version of my app, I need to deserialize the myobject.xml, but
my class has changed due to new app requirements:

// version 2
class
{
string myString;
int myInt;
bool myBool;
}

Now, it won't deserialize anymore. In order to guarantee product update
compatibility, do I have to maintain all previous versions of my serialized
classes in my app and do try-catch-try-catch blocks until the correct
version can be read?

Any hints are appreciated

Urs


.


There is no way to do this as you really want. But take a look at the
Header[] arguments of the serialize/deserialize methods - ,these headers
will keep track of all objects within the file etc, allowing many objects to
be serialized to the same file - maybe you could delete old object types and
update them with the new ones by catching the headers callback - I haven't
thought this through much though...

James
 
N

Nicholas Paldino [.NET/C# MVP]

James,

This isn't completely true. To handle version differences, it is
recommended that you implement the ISerializable interface on your object,
and then handle the information that is in the SerializationInfo instance
that is lacking due to version differences.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

James said:
Urs Vogel said:
Hi

I'm wondering if there's a technique to deserialize objects which were
serialized with an earlier version of the class. Example:

// version 1
class
{
string myString;
int myInt;
}

is serialized to myobject.xml

In an update version of my app, I need to deserialize the myobject.xml, but
my class has changed due to new app requirements:

// version 2
class
{
string myString;
int myInt;
bool myBool;
}

Now, it won't deserialize anymore. In order to guarantee product update
compatibility, do I have to maintain all previous versions of my serialized
classes in my app and do try-catch-try-catch blocks until the correct
version can be read?

Any hints are appreciated

Urs


.


There is no way to do this as you really want. But take a look at the
Header[] arguments of the serialize/deserialize methods - ,these headers
will keep track of all objects within the file etc, allowing many objects to
be serialized to the same file - maybe you could delete old object types and
update them with the new ones by catching the headers callback - I haven't
thought this through much though...

James
 
J

James

Nicholas Paldino said:
James,

This isn't completely true. To handle version differences, it is
recommended that you implement the ISerializable interface on your object,
and then handle the information that is in the SerializationInfo instance
that is lacking due to version differences.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

James said:
Urs Vogel said:
Hi

I'm wondering if there's a technique to deserialize objects which were
serialized with an earlier version of the class. Example:

// version 1
class
{
string myString;
int myInt;
}

is serialized to myobject.xml

In an update version of my app, I need to deserialize the
myobject.xml,
but
my class has changed due to new app requirements:

// version 2
class
{
string myString;
int myInt;
bool myBool;
}

Now, it won't deserialize anymore. In order to guarantee product update
compatibility, do I have to maintain all previous versions of my serialized
classes in my app and do try-catch-try-catch blocks until the correct
version can be read?

Any hints are appreciated

Urs


.


There is no way to do this as you really want. But take a look at the
Header[] arguments of the serialize/deserialize methods - ,these headers
will keep track of all objects within the file etc, allowing many
objects
to
be serialized to the same file - maybe you could delete old object types and
update them with the new ones by catching the headers callback - I haven't
thought this through much though...

James

ok - as you on this thread can you tell me a good use for the header[] is? -
Like I said in post, I have not give this much thought and obviously what
you say about implementing the interface is correct, but what use for the
header[] - is it simply to retrieve specific objects etc?

thanks
 
U

Urs Vogel

Kevin

The problem exists for both, binary and soap serialization. XSL still would
require some additional deliverables for updates, very hard to control.
Users expect updateds versions to run smoothly without the requirement of
converting data. I think Nicholas Paldinos comments are leading the right
way.

Thanks,
Urs
 
U

Urs Vogel

Thanks for your help, I will follow this track

Urs

Nicholas Paldino said:
James,

This isn't completely true. To handle version differences, it is
recommended that you implement the ISerializable interface on your object,
and then handle the information that is in the SerializationInfo instance
that is lacking due to version differences.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

James said:
Urs Vogel said:
Hi

I'm wondering if there's a technique to deserialize objects which were
serialized with an earlier version of the class. Example:

// version 1
class
{
string myString;
int myInt;
}

is serialized to myobject.xml

In an update version of my app, I need to deserialize the
myobject.xml,
but
my class has changed due to new app requirements:

// version 2
class
{
string myString;
int myInt;
bool myBool;
}

Now, it won't deserialize anymore. In order to guarantee product update
compatibility, do I have to maintain all previous versions of my serialized
classes in my app and do try-catch-try-catch blocks until the correct
version can be read?

Any hints are appreciated

Urs


.


There is no way to do this as you really want. But take a look at the
Header[] arguments of the serialize/deserialize methods - ,these headers
will keep track of all objects within the file etc, allowing many
objects
to
be serialized to the same file - maybe you could delete old object types and
update them with the new ones by catching the headers callback - I haven't
thought this through much though...

James
 

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