locked
Changing a namespace causes errors when using "BinaryFormatter.Deserialize" to reload object data saved while defined under a different namesapce. RRS feed

  • Question

  • BinarayFormatter.Deserialize causes an exception when trying to reload object data that is now defined under a different namespace from the one when it was saved.  The error message is: "The ObjectManager found an invalid number of fixups.  This is usually indicates a problem in the formatter".

    Does anyone know if there is a work around foir this?

    There area simialar probelms if the name of the assembly is changed.
    Wednesday, January 6, 2010 3:19 PM

Answers

  • The binary formatter tries to re-create the class it serialized, if you renamed its namespace it has a different FQN now so the binary formatter can't find it anymore. By writing a custom SerializationBinder you should be albe to redirect the missing classes to their new home.

    • Proposed as answer by Harry Zhu Monday, January 11, 2010 7:13 AM
    • Marked as answer by Harry Zhu Wednesday, January 13, 2010 1:39 AM
    Wednesday, January 6, 2010 3:27 PM
  • You should look at the SerializationBinderClass
    • Proposed as answer by Harry Zhu Monday, January 11, 2010 7:13 AM
    • Marked as answer by Harry Zhu Wednesday, January 13, 2010 1:39 AM
    Wednesday, January 6, 2010 3:29 PM

All replies

  • The binary formatter tries to re-create the class it serialized, if you renamed its namespace it has a different FQN now so the binary formatter can't find it anymore. By writing a custom SerializationBinder you should be albe to redirect the missing classes to their new home.

    • Proposed as answer by Harry Zhu Monday, January 11, 2010 7:13 AM
    • Marked as answer by Harry Zhu Wednesday, January 13, 2010 1:39 AM
    Wednesday, January 6, 2010 3:27 PM
  • You should look at the SerializationBinderClass
    • Proposed as answer by Harry Zhu Monday, January 11, 2010 7:13 AM
    • Marked as answer by Harry Zhu Wednesday, January 13, 2010 1:39 AM
    Wednesday, January 6, 2010 3:29 PM
  • class Binder : SerializationBinder {
    	public override Type BindToType(string assemblyName, string typeName) {
    		typeName = typeName.Replace("OldNameSpace", "NewNameSpace");
    		return Type.GetType(typeName);
    	}//method
    }//class
    
    

    be careful that "OldNameSpace" doesn't match anything else
    Thursday, August 18, 2011 10:24 AM
  • This isn't working for me. does anyone else have any other suggestions?

    dee allen

    This isn't working for me. I've created a class and implemented SerializationBinder. Example:

    <pre>

    class TypeNameConverter : SerializationBinder

    {

    public override Type BindToType(string assemblyName, string typeName)

    {

    typeName = typeName.Replace("MyOldNamespace", "MyNewNamespace");

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

    }

    }

    </pre>

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

    • Edited by d.allen101 Thursday, October 4, 2012 11:31 PM
    Thursday, October 4, 2012 11:20 PM