BinaryFormatter Version mismatch

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, all:

I've seen numerous questions and answers about this topic on the web, but
none of them quite fit to my case. My application is a business process
model (like approval process) using ASP.NET. Each transaction, I store
related data in the database as a blob. When I retreive the data from
database, deserialization fails and I get this error:
"BinaryFormatter Version incompatibility. Expected Version 1.0. Received
Version 49.0."
Looks like there is an ASCII and binary problem (ASCII value 1 is 49), but I
can't get around this. Can I somehow set the BinaryFormatter not to check the
version information? Can I make it to skip this version check?

Any help will be appreciated.

Thanks

Sung.
 
pak20116 said:
I've seen numerous questions and answers about this topic on the web, but
none of them quite fit to my case. My application is a business process
model (like approval process) using ASP.NET. Each transaction, I store
related data in the database as a blob. When I retreive the data from
database, deserialization fails and I get this error:
"BinaryFormatter Version incompatibility. Expected Version 1.0. Received
Version 49.0."
Looks like there is an ASCII and binary problem (ASCII value 1 is 49), but I
can't get around this. Can I somehow set the BinaryFormatter not to check the
version information? Can I make it to skip this version check?

If the version information is garbled, I see no reason to believe the
rest of your data would be okay.

I would split the problem into two halves:

1) Make sure you can serialize to a byte array and then deserialize
again.

2) Make sure you can store a byte array in your database and retrieve
it again.

Once you've worked out which of these stages is the problem, it'll be a
lot easier to fix.
 
Hi,
Thank you for your quick response.
I apologize for mulitple posts. I'll be more careful from now on.
I tried those two and both work fine. The problem I'm facing is that I
serialized and entered data few weeks ago and I'm trying to retreive them.
If I make data entry now, it works fine. Do you think maybe data in the
database is corrupted?

Thanks.
 
pak20116 said:
Thank you for your quick response.
I apologize for mulitple posts. I'll be more careful from now on.
I tried those two and both work fine. The problem I'm facing is that I
serialized and entered data few weeks ago and I'm trying to retreive them.
If I make data entry now, it works fine. Do you think maybe data in the
database is corrupted?

Either that, or you've changed the contents of your class since you
saved the data into the database.

I don't know how versioning works with BinaryFormatter, but if you've
changed your class (e.g. added a field) then I think you'll have to add
support in to deserialize "old" versions.
 
How would you go about adding support for deserializing older versions of the
saved data? This is the exact problem I am having. I saved data several
days ago and added a field to my class. Now when deserializing I get an
exception error. Do you have an example of how this solution can be
implemented? Help would be greatly appreciated as resolving this issue is
critical to my application.
 
Steve Teeples said:
How would you go about adding support for deserializing older versions of the
saved data? This is the exact problem I am having. I saved data several
days ago and added a field to my class. Now when deserializing I get an
exception error. Do you have an example of how this solution can be
implemented? Help would be greatly appreciated as resolving this issue is
critical to my application.

Unfortunately I don't know much about binary formatting - I suspect
that without having already put in support in the old code for
specifically serializing in a known format, you may well be stuck.

When you say it's critical to your application, do you mean the ability
to add to your class and still be able to deserialize is critical, or
just to extract this data? If it's the latter, I'd suggest going back
to an older version of the class, deserialising and saving the data in
another (more explicit) way, then putting the fields back in, loading
the data again and reserializing.
 
I'm creating a test tool that over time may require tweaks to the class
components which contain the test requirement data that is serialized to
disk. I want to be able to update these classes over time as necessary but
still read data from older versions of the "serialized" data. Is there
another solution maybe?
 
Steve Teeples said:
I'm creating a test tool that over time may require tweaks to the class
components which contain the test requirement data that is serialized to
disk. I want to be able to update these classes over time as necessary but
still read data from older versions of the "serialized" data. Is there
another solution maybe?

Well, you could implement ISerializable and have a constructor
accepting SerializationInfo and StreamingContext, as documented in
ISerializable, but unless you particularly require the automatic
serialization or your class has a lot of complex fields, I'd be tempted
to write methods which loaded and saved in a custom format yourself.
 
I think it would be easiest to use a custom method given the limitations of
serialization and versioning. Thanks for the time and suggestions.
 
Back
Top