How to create a SerializationBinder for the Binary Formatter that handles the moving of types from one assembly and namespace to another

This could work (instead of your override). public override Type BindToType(string assemblyName, string typeName) { var m = Regex.Match(typeName, @”^(?<gen>[^\[]+)\[\[(?<type>[^\]]*)\](,\[(?<type>[^\]]*)\])*\]$”); if (m.Success) { // generic type var gen = GetFlatTypeMapping(m.Groups[“gen”].Value); var genArgs = m.Groups[“type”] .Captures .Cast<Capture>() .Select(c => { var m2 = Regex.Match(c.Value, @”^(?<tname>.*)(?<aname>(,[^,]+){4})$”); return BindToType(m2.Groups[“aname”].Value.Substring(1).Trim(), m2.Groups[“tname”].Value.Trim()); }) .ToArray(); return gen.MakeGenericType(genArgs); } return GetFlatTypeMapping(assemblyName,typeName); } … Read more

What are the differences between the XmlSerializer and BinaryFormatter

The reason a binary formatter is able to deserialize directly to an interface type is because when an object is originally serialized to a binary stream metadata containing type and assembly information is stuck in with the object data. This means that when the binary formatter deserializes the object it knows its type, builds the … Read more

Is it possible to do .NET binary serialization of an object when you don’t have the source code of the class?

You could create a serialization surrogate. Imagine that we have a class defined in a referenced assembly that we have no control over that looks like this: public class Person { public string Name { get; set; } public int Age { get; set; } public DriversLicense License; } // An instance of this type … Read more