After changing the namespace of my class I can no longer deserialize the objects. I've implemented SerializationBinder
. Example:
public class TypeNameConverter : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
typeName = typeName.Replace("MyOldNamespace", "MyNewNamespace");
return Type.GetType(string.Format("{0}, {1}", typeName, assemblyName));
}
}
BinaryFormatter bf = new BinaryFormatter();
bf.Binder = new TypeNameConverter();
The exception I get is:
'System.Runtime.Serialization.TypeLoadExceptionHolder' cannot be converted to type 'MyNewNamespace.MyClass'
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…