Deserialization type load exception even when using a serialization binder

  • Thread starter Thread starter john_smith_677
  • Start date Start date
J

john_smith_677

Hi,

I moved some code from my project to a separate assembly. I have some
saved definitions that were saved using regular .net serialization.
When trying to open the saved definitions, I get type load
exceptions. I am getting around this by implementing my own
SerializationBinder and forwarding the typenames to the new assembly.
I successfully forward all the types but yet I still get a type load
exception later on in the deserialization. It seems the formatter is
still referencing the old type name instead of the forwarded one. I
should also mention that the type that generates the error is a
parameter to another type which is generic. I can't think of a way
around this and so I can't open any saved definitions right now. I'm
hoping one of you guys knows a solution.

Here's the stack trace of the framework part of the exception:
at System.Reflection.Assembly.GetType(String name, Boolean
throwOnError, Boolean ignoreCase)
at System.UnitySerializationHolder.GetRealObject(StreamingContext
context)
at
System.Runtime.Serialization.ObjectManager.ResolveObjectReference(Objec
tHolder holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize
(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck,
Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserial
ize(Stream serializationStream, HeaderHandler handler, Boolean fCheck,
Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserial
ize(Stream serializationStream)

Thanks
 
Are you sure your BindToType is getting the new type from the correct
assembly?
It might help to see the code.
 
It turns out that one of the saved objects had an instance field of
system.type that points to one of the old types. That's why it wasn't
going through the serialization binder.

Thanks for you help.
 
Back
Top