I have a project which uses BinaryFormatter to serialize a collection of structs with string and bool? datatypes.
The serialization/deserialization works fine, however if I were to change the assembly which does the work it fails to deserialize because of the header in the binary file indicating that it requires Assembly x
instead of Assembly y
to handle the data.
Is it possible to setup the serialization/deserialization to be assembly agnostic?
You can control how the binary formatter resolves its types by assigning a custom SerializationBinder to the formatter. In this way, you won't need to mess with the AppDomain's resolve events and you eliminate the risk of unexpected side effects from that.
There is a detailed example at MSDN.