The BinaryFormatter will include the full type name (assembly and namespace included) in the output. You need to use a custom SerializationBinder to read it:
public class CustomBinder : SerializationBinder
{
static string assemblyToUse = typeof (MyObject).Assembly.FullName;
public override Type BindToType(string assemblyName, string typeName)
{
if (typeName.EndsWith("MyType"))
return typeof(MyTypeInThisAssembly);
return base.BindToType(assemblyName, typeName);
}
}
var formatter = new BinaryFormatter{Binder = new CustomBinder()};
var obj = formatter.Deserialize(...)
This has the downside of having to include the code for the CustomFormatter in every assembly tho, which I'm guessing is not what you want. This probably leaves you with having to use a custom format output (like JSON or protocol buffers )