Is it possible to recover an object serialized via “BinaryFormatter” after changing class names? [duplicate]

Yes, it is possible. You can use the SerializationBinder class. Something like this:

public class ClassOneToNumberOneBinder : SerializationBinder
    public override Type BindToType(string assemblyName, string typeName)
        typeName = typeName.Replace(

        assemblyName = assemblyName.Replace("MyNamespace", "MyNamespace.Class");

        return Type.GetType(string.Format("{0}, {1}", typeName, assemblyName));

BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Binder = new ClassOneToNumberOneBinder();

Code example adapted from this answer.

Leave a Comment