473,405 Members | 2,287 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,405 software developers and data experts.

Serialization missing data

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
Nov 17 '05 #1
4 1791
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
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

Nov 17 '05 #2
mdb
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in news:Op**************@TK2MSFTNGP14.phx.gbl:
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?

--
-mdb
Nov 17 '05 #3
This is similar to another thread ("New versions vs. serialization"), which
might (might not) be of help:
http://groups-beta.google.com/group/...da7fbe5e32fc3e
"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in news:Op**************@TK2MSFTNGP14.phx.gbl:
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?

--
-mdb

Nov 17 '05 #4
mdb
"Fred Mellender" <no****************@frontiernet.net> wrote in
news:Be*************@news02.roc.ny:
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.

--
-mdb
Nov 17 '05 #5

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

Similar topics

0
by: Dave | last post by:
I was curious to know if anyone has suggestions about maintaining various versions of class definitions when using serialization to save data. Is there a "standard" way of handling backward...
2
by: reycri | last post by:
I have a .Net class (a collection) that already supports serialization. It implements ISerializable... Now, I need it to also support the COM interface IPersistStream. Among other things, I need...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
0
by: Alberto Grosso Nicolin | last post by:
We have the following XML schema: there's a root element (Response) with of a single child element (Result). ...
5
by: Alfonso Morra | last post by:
I have the following data types: typedef union { long l ; double f; char* s ; void* p ; } Value ; typedef struct {
2
by: ven | last post by:
I have used C# binary formatter to serialize and deserialize a data structure. However, for the same data format( used by the first executable, the same *.CS files), the second executable gives an...
2
by: Ron M. Newman | last post by:
Hi, I have a simple class that has a Hashtable. the hashtable has a couple of key/value pairs where the key is a string and the value is also a strong. I have at the top of that class. ...
9
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, Just before I invent my own solution... :-) I'm developing a program where I use binary serialization of the data the program holds. Know and then the serialized objecst will be modified,...
5
by: RobinS | last post by:
I want to serialize a class that I am using to retain some information the user types into a screen. I have 3 questions. 1) I serialized it as XML to start with. This works, but how do I...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.