BinaryFormatter.Deserialize after signing of assembly fails

  • Thread starter Thread starter Henrik Skak Pedersen
  • Start date Start date
H

Henrik Skak Pedersen

Hello,

I have a class which is beeing serialized/deserialized using the
BinaryFormatter class. That has been working with no problems until I signed
all my assemblies. Now I get a SerializationException when I try to
Deserialize the class which has been serialized before the signing. So what
is best practice in my situation?

Do I have to convert all my saved classes or do I write a
SerializationBinder to handle it runtime?

If I delete all my data and run fra scratch it works fine until I compile my
assembly. Then the assembly gets a new versioand it fails on the version.
Why do I get this error now, i did'nt get it before I signed the assembly?

Best regards

Henrik Skak Pedersen
 
I haven't tried to use a SerializationBinder to convert a stream from a
unsigned to a signed assembly but I can't think of a reason why it would not
work. You will definitely want to use one to handle the versioning issues
when you deserialize a stream using a later version of the assembly when it
was originally serialized with an earlier version of the stream.
 
Hi David,

Thank you very much for your email.

All my assemblies get a new version number everytime it get compiled. I am
using the following attribute:
[assembly: AssemblyVersion("1.0.*")]


I guess that is a problem then? Because my data is outdated very fast?

Best regards

Henrik Skak Pedersen
 
Henrik Skak Pedersen said:
Hi David,

Thank you very much for your email.

All my assemblies get a new version number everytime it get compiled. I am
using the following attribute:
[assembly: AssemblyVersion("1.0.*")]


I guess that is a problem then? Because my data is outdated very fast?

It's not a problem so long as you use a SerializationBinder to return the
current type defined in the assembly. Of course, this assumes that the new
type is compatible with the old type. If not, then the type that changed
ought to implement the ISerializable interface and handle its own
serialization to/from the stream.
 
Back
Top