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

Workaround for versioning of serialization file?

I've got a VB2005 program that persists some data structures by
serializing to a disk file and then reading this file whenever the
program restarts.

I tend to 'stage' my program development by creating a new project
every so often and copying the files from the previous project version
into the new project. (So I have an intact previous version of the
project even if the new version goes off in a direction that
ultimately proves unsuccessful.)

This approach normally works well but is giving me a problem with the
serialized file with a DirectCast error whenever I've just created a
new project. The relevant line of code is:

MyObject = DirectCast(bf.Deserialize(fs), MyObjectType)

where bf is the binary formatter and fs is a defined filestream.

If the previous project version was named say Project500 and the new
one is Project600 then the error on trying to start Project600 for the
first time is:

'Cannot cast Project500.MyObject to Project600.MyObject'

Presumably the serialized object has its parent project name embedded
in its binary structure and objects to being deserialized into a
nominally different project.

Is there any way of working around this?
Jul 25 '07 #1
1 1057
John,

You can use the System.Runtime.Serialization.SerializationBinder class.

Here is an article that discusses this topic:

http://msdn.microsoft.com/msdnmag/issues/02/09/net/

Kerry Moorman
"John Dann" wrote:
I've got a VB2005 program that persists some data structures by
serializing to a disk file and then reading this file whenever the
program restarts.

I tend to 'stage' my program development by creating a new project
every so often and copying the files from the previous project version
into the new project. (So I have an intact previous version of the
project even if the new version goes off in a direction that
ultimately proves unsuccessful.)

This approach normally works well but is giving me a problem with the
serialized file with a DirectCast error whenever I've just created a
new project. The relevant line of code is:

MyObject = DirectCast(bf.Deserialize(fs), MyObjectType)

where bf is the binary formatter and fs is a defined filestream.

If the previous project version was named say Project500 and the new
one is Project600 then the error on trying to start Project600 for the
first time is:

'Cannot cast Project500.MyObject to Project600.MyObject'

Presumably the serialized object has its parent project name embedded
in its binary structure and objects to being deserialized into a
nominally different project.

Is there any way of working around this?
Jul 25 '07 #2

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

Similar topics

1
by: Mike | last post by:
I'm having a problem with serializing between different versions of classes. I've read the many posts on handling versioning by implementing ISerializable but unforunately we shipped the first few...
0
by: Johann Blake | last post by:
I have an application that runs on a web server that sends data to clients over a TCP socket. The data comes from a class that has been serialized. The class exists in a library (a DLL). The...
5
by: Tamir Khason | last post by:
Hi, all Two classes Foo1 and Foo2 Foo1 uses Foo2 as reference Both are strong name signed with the same key pair I'm performing Binary Serialization of object inside Foo2 from Foo1 as following:...
1
by: Tamir Khason | last post by:
I have a base class MyBaseFoo with some properties, methods etc. I have some derived classes, implements small part of MyBaseFoo and a lot of their own. In order to ensure proper deserialization...
1
by: zacks | last post by:
Am using VB.NET 2005. I have a solution that has four projects. Two projects are standard windows applications. One is a class library that is shared by the two windows application projects, it...
4
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
I have seen many articles describing why versioning web services are important. I have a scenario that I would like to propose to seek a solution. I have a publicly consumable web service. Two...
1
by: Coaster | last post by:
orig ref here http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/ff29cc370678911d/c0db5b7e3da283b9?lnk=st&q=gac+assembly+new+version&rnum=7#c0db5b7e3da283b9...
3
by: =?Utf-8?B?TWFydGluIEtvY2g=?= | last post by:
1st I serialize a DataSet (contains 14 DataTables) into file, with BinaryFormatter. 2nd I change some columns in a DataTable. 3rd When I now Deserialize the DataSet from bin file got I...
1
by: Tarscher | last post by:
Hi all, i want to save my application to a file with a BinaryFormatter . I have some questions how the BinaryFormatter will work when the I update my application. How can I make sure that I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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,...
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.