Can't deserialize with binaryFormatter after changing namespace of class

前端 未结 1 1570
日久生厌
日久生厌 2020-12-10 15:31

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

public class T         


        
相关标签:
1条回答
  • 2020-12-10 15:59

    you forgot to replace the assembly name:

    class TypeNameConverter : SerializationBinder
    {
        public override Type BindToType(string assemblyName, string typeName)
        {
            typeName = typeName.Replace("MyOldNamespace", "MyNewNamespace");
            assemblyName = assemblyName.Replace("MyOldNamespace", "MyNewNamespace");
            return Type.GetType(string.Format("{0}, {1}", typeName, assemblyName));
        }
    }
    
    0 讨论(0)
提交回复
热议问题