473,769 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1806
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.co m

"mdb" <m_b_r_a_y@c_t_ i_u_s_a__d0t__c om> wrote in message
news:Xn******** *************** *****@207.46.24 8.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.c om> wrote
in news:Op******** ******@TK2MSFTN GP14.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__c om> wrote in message
news:Xn******** *************** *****@207.46.24 8.16...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in news:Op******** ******@TK2MSFTN GP14.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************ ****@frontierne t.net> wrote in
news:Be******** *****@news02.ro c.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
825
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 compatibility with previous version file structures? I don't have problems within the program itself, just with loading data from files created with previous versions of the class definition. It seems that if a change as minor as changing a property...
2
1980
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 to be able to pass instances of this class to methods of queued components (in COM+). I want to "piggy back" my implementation of IPersistStream to what is already being used for serialization. So, in the Save() method of IPersistStream, the...
37
5021
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 signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well for us.
0
1707
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). ---------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <xs:schema id="TaskRequest" targetNamespace="http://xyz.com/TaskResponse/1.0" elementFormDefault="qualified" xmlns="http://xyz.com/TaskResponse/1.0"
5
508
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
1835
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 error referring to the first assembly name missing, when trying to deserialize the *.dat file. When I rename the second executable to the first executable, it works fine. the *.dat file was created by the first executable. Could any one help...
2
1339
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. when I try to serialize it with XmlSerializer, I get only the "class boundary" but my hashtable member doesn't get serialized. Hashtable is Serializable, at least that's what the documentation says.
9
1257
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, e.g. with a new field, or perhaps the removal of a field. Depending on the changes, the program will not be able to deserialize the stored data. Is there any technique I can read about somewhere dealing with this issue.
5
4327
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 serialize the strings so that they are not messed up if they have XML in them, or control characters? Is there a way to do that in XML, or do I have to use BinaryFormatters? 2) So I tried using a binary formatter, and it won't serialize/deserialize...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10050
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.