Deserialization, SerializationBinder and Insufficient State

  • Thread starter Thread starter Mark Olbert
  • Start date Start date
M

Mark Olbert

I need some help dealing with deserializing objects using BinaryFormatter when the assembly version changes. Nothing about the
structure of the class being deserialized has changed; just the version of the assembly that defines it.

My understanding is that, by default, BinaryFormatter.Deserialize() blows up with an assembly not found exception if you try to
deserialize an object created with an earlier version of the same, unchanged assembly. Personally, I think that's a weird default.
Or maybe the folks who wrote that code always get their programs right the first time, so they never deal with assembly version
changes :).

In any event, it looks like the SerializationBinder class exists to resolve this problem, by "mapping" one type to another.

In my app I've derived a class from SerializationBinder which handles the version changes. It returns the correct new Type for each
old Type it's given.

However, Deserialize() is still blowing up with a FileNotFound exception, claiming that one of the required assemblies, or a
dependency of same, cannot be found.

1) How can I verify precisely which version of the "missing" assembly is being sought? I've run fuslogvw.exe, but it's not
displaying anything.

2) How can I determine if it's a dependent assembly that's missing? And, if that's the problem, how do I inform the deserialization
engine where to find the new assembly?

3) Am I on the right track using SerializationBinder to solve this problem? If not, what should I do?

- Mark
 
Hi

You may try to the configuration in the link below for the tool Fuslogvw.
Assembly Binding Log Viewer (Fuslogvw.exe)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/htm
l/cpgrfFusionLogViewerFuslogvwexe.asp

Also if you did not make any change to the serialization class, why you
want to change the version, you can keep the version via setting in he
AssemblyInfo.cs file.

Here is a link about the SerializationBinder.
You make a new version of a type. In this case, you want to deserialize any
already-serialized objects into the new version of the type.
Overriding the Assembly or Type When Deserializing an Object

Run-time Serialization, Part 3
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

Here are other references.
Run-time Serialization
http://msdn.microsoft.com/msdnmag/issues/02/04/net/

Run-time Serialization, Part 2
http://msdn.microsoft.com/msdnmag/issues/02/07/net/default.aspx

Object Serialization in the .NET Framework
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/objserializ.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top