473,397 Members | 1,950 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,397 software developers and data experts.

Deserialization of changed objects

Hi

Let's assume that I have an object_V1 (version 1) serialized to disk. Later,
the class for object_V1 will change to object_V2, having some more members.
Now, I would like to read my previously saved objects of type object_V1 into
object_V2, which (logically) now throws an exception.

I tried to make use of the HeaderHandler, but this gives me only access to
the methods, not the members. I also tried to inherit object_V1 into
object_V2, which didn't work either.

Is there an way to control this deserialization process, any samples around?

Any hints ar appreciated.

Thanks. Urs.
Nov 20 '05 #1
3 1070
Are you using basic XML serialization? You should be able to add attributes
to your object_V2 class definition and property definitions that will map
the XML from object_V1 to object_V2.

Controlling XML Serialization Using Attributes
http://msdn.microsoft.com/library/de...attributes.asp
Overriding XML Serialization
http://msdn.microsoft.com/library/de...ridesclass.asp
"Urs Vogel" <ur******@yahoo.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
Hi

Let's assume that I have an object_V1 (version 1) serialized to disk. Later, the class for object_V1 will change to object_V2, having some more members. Now, I would like to read my previously saved objects of type object_V1 into object_V2, which (logically) now throws an exception.

I tried to make use of the HeaderHandler, but this gives me only access to
the methods, not the members. I also tried to inherit object_V1 into
object_V2, which didn't work either.

Is there an way to control this deserialization process, any samples around?
Any hints ar appreciated.

Thanks. Urs.

Nov 20 '05 #2
You would have to implement ISerializable in Object_V2.

Object_V2, GetObjectData - would serialize, and the protected
new(Serialization Info, StreamingContext context) would deserialize (hope my
memory is holding up to the exact param list ... it's been a while since I
did this.

So the V2 - V1 members would get a default value assignment in this New
function.

_ Sahil Malik
Independent Consultant.
"Urs Vogel" <ur******@yahoo.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
Hi

Let's assume that I have an object_V1 (version 1) serialized to disk. Later, the class for object_V1 will change to object_V2, having some more members. Now, I would like to read my previously saved objects of type object_V1 into object_V2, which (logically) now throws an exception.

I tried to make use of the HeaderHandler, but this gives me only access to
the methods, not the members. I also tried to inherit object_V1 into
object_V2, which didn't work either.

Is there an way to control this deserialization process, any samples around?
Any hints ar appreciated.

Thanks. Urs.

Nov 20 '05 #3
You would have to implement ISerializable in Object_V2.

Object_V2, GetObjectData - would serialize, and the protected
new(Serialization Info, StreamingContext context) would deserialize (hope my
memory is holding up to the exact param list ... it's been a while since I
did this.

So the V2 - V1 members would get a default value assignment in this New
function.

_ Sahil Malik
Independent Consultant.
"Urs Vogel" <ur******@yahoo.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
Hi

Let's assume that I have an object_V1 (version 1) serialized to disk. Later, the class for object_V1 will change to object_V2, having some more members. Now, I would like to read my previously saved objects of type object_V1 into object_V2, which (logically) now throws an exception.

I tried to make use of the HeaderHandler, but this gives me only access to
the methods, not the members. I also tried to inherit object_V1 into
object_V2, which didn't work either.

Is there an way to control this deserialization process, any samples around?
Any hints ar appreciated.

Thanks. Urs.

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
0
by: Dan Noel | last post by:
I am implementing a DataStore/Settings object that stores objects in XML by serializing the objects in XML and then associating these objects with key names. At some later point, I want to...
5
by: Urs Vogel | last post by:
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 ...
2
by: Urs Vogel | last post by:
Hi Let's assume that I have an object_V1 (version 1) serialized to disk. Later, the class for object_V1 will change to object_V2, having some more members. Now, I would like to read my...
6
by: Nick Z. | last post by:
I need my program to start as fast as possible. Will deserialization a few settings using binary deserialization affect that? Or should I keep these settings in XML, will that be any better? ...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.