473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Deserialization

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
5 4911

"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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Serg | last post by:
Hi. I have a problem with deserialization decimal value. I have a simple class: public class A { public decimal d; } The serialization a value 0.00000001 is OK. The file is
3
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing...
2
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on...
3
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database...
3
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
8
by: ashoksrini | last post by:
Hi All, I have the below requirement and would like to get some feeback from the group on the best way to implement: 1. I have WSDL defined exposing few web services. 2. We dont have a...
5
by: Greg Allen | last post by:
I am consuming a web service and using the generated Reference.cs to access the service and the objects associated with it. I have run into a problem where some inherited classes are not being...
7
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.