By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,673 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,673 IT Pros & Developers. It's quick & easy.

Deserialization

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Urs Vogel" <ur******@yahoo.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
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
Nov 13 '05 #2

P: n/a
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]
- ni**************@exisconsulting.com

"James" <Ja***@NOSPAMjenkins2040.freeserve.co.uk> wrote in message
news:ec*************@TK2MSFTNGP10.phx.gbl...

"Urs Vogel" <ur******@yahoo.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
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

Nov 13 '05 #3

P: n/a

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:u8**************@TK2MSFTNGP11.phx.gbl...
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]
- ni**************@exisconsulting.com

"James" <Ja***@NOSPAMjenkins2040.freeserve.co.uk> wrote in message
news:ec*************@TK2MSFTNGP10.phx.gbl...

"Urs Vogel" <ur******@yahoo.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
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
Nov 13 '05 #4

P: n/a
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

"Kevin Conroy" <kc******@prolist.com> schrieb im Newsbeitrag
news:uj**************@TK2MSFTNGP10.phx.gbl...
In an update version of my app, I need to deserialize the myobject.xml, but
my class has changed due to new app requirements:


Since you using Xml serialization, you could always create an XSL

stylesheet which can transform from the old format to the new format. Perhaps defining a default value of false to the boolean value or something. I could be
mistaken, but I don't think that you have to have every single field defined when you deserialize. The Xml Serialization portion of the .NET framework
will just leave unserialized properties alone.

Of course this is an issue if your class is expecting a value to be defined for the boolean field (or what have you). This is why I'd suggest using an
Xsl.

Or, you could make another version of the object that is more akin to the
old style. This object could then automatically create a version of the new object and set up the values correctly. This is like a programmatic version of doing an Xsl transform on the serialized Xml and thus is only a better
solution over Xsl if you need to perform a complex operation to convert the old serialization to the new format and cannot do it in Xsl.

Just my 2 cents.
Kevin Conroy
Programmer/Analyst

Nov 13 '05 #5

P: n/a
Thanks for your help, I will follow this track

Urs

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>
schrieb im Newsbeitrag news:u8**************@TK2MSFTNGP11.phx.gbl...
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]
- ni**************@exisconsulting.com

"James" <Ja***@NOSPAMjenkins2040.freeserve.co.uk> wrote in message
news:ec*************@TK2MSFTNGP10.phx.gbl...

"Urs Vogel" <ur******@yahoo.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl...
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


Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.