After changing the namespace of my class I can no longer deserialize the objects. I've implemented SerializationBinder. Example:

publicclassTypeNameConverter:SerializationBinder{publicoverrideTypeBindToType(string assemblyName,string typeName){
          typeName = typeName.Replace("MyOldNamespace","MyNewNamespace");returnType.GetType(string.Format("{0}, {1}", typeName, assemblyName));}}BinaryFormatter bf =newBinaryFormatter();
bf.Binder=newTypeNameConverter();

The exception I get is 'System.Runtime.Serialization.TypeLoadExceptionHolder' cannot be converted to type 'MyNewNamespace.MyClass'

 

you forgot to replace the assembly name:

classTypeNameConverter:SerializationBinder{publicoverrideTypeBindToType(string assemblyName,string typeName){
        typeName = typeName.Replace("MyOldNamespace","MyNewNamespace");
        assemblyName = assemblyName.Replace("MyOldNamespace","MyNewNamespace");returnType.GetType(string.Format("{0}, {1}", typeName, assemblyName));}}

相关文章:

  • 2021-05-11
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2021-04-29
  • 2022-01-24
  • 2021-10-07
猜你喜欢
  • 2022-01-02
  • 2021-10-13
  • 2021-10-20
  • 2022-12-23
  • 2022-01-17
  • 2021-08-01
  • 2021-10-29
相关资源
相似解决方案