I am curious to know how to โsplitโ deserialization using the binary formatting assembly format using FormatterAssemblyStyle.Full.
the documentation points to this:
In full mode, the assembly used during deserialization must exactly match the assembly used during serialization.
I thought that if I serialize an object (_person, which is a simple class with value type fields) with assembly version 1.0.0.0, try to deserialize using assembly v1.2.0.0 (update AssemblyInfo.cs), I would get a deserialization exception . However, it is successfully deserialized.
Did I miss something?
I serialize to a file using the following:
BinaryFormatter formatter = new BinaryFormatter(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full; using (Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { formatter.Serialize(stream, _person); stream.Close(); }
and then deserialization using the following:
BinaryFormatter formatter = new BinaryFormatter(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full; using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { _person = (Person)formatter.Deserialize(stream); stream.Close(); }
I also noticed that the serialized file created using FormatterAssemblyStyle.Full and FormatterAssemblyStyle.Simple contains full version information (e.g. Version 1.0.0.0 Culture = neutral, PublicKeyToken = null). I thought Simple won't add all this information? (see section formatters and names names from this )
Update 1:
The only difference I've seen so far is that if I use Simple, then I donโt need to place the OptionalField attribute for the new fields in the serialized class so that it successfully deacilates the old versions. If I use Full, it throws an exception unless I put the OptionalField attribute in new fields. Is this the only difference if you use assemblies that are not strong with the name
See more details.
Thank you in advance