By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,255 Members | 1,701 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,255 IT Pros & Developers. It's quick & easy.

Workaround for versioning of serialization file?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.