title: C# Binary serialization and AssemblyFormat with FormatterAssemblyStyle.Full
body: <p>I am curious to know how to "break" deserialization using the assembly format of the binary formatter with FormatterAssemblyStyle.Full. </p>
  
  <p>The <a href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&amp;l=EN-US&amp;k=k%28SYSTEM.RUNTIME.SERIALIZATION.FORMATTERS.FORMATTERASSEMBLYSTYLE.FULL%29;k%28FULL%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK,VERSION=V4.0%22%29;k%28DevLang-CSHARP%29&amp;rd=true" rel="nofollow noreferrer">documentation</a> states for this: </p>
  
  <blockquote>
    <p>In full mode, the assembly used during deserialization must match
    exactly the assembly used during serialization.</p>
  </blockquote>
  
  <p>I thought that if I serialize an object (_person which is a simple class with value type fields) with version 1.0.0.0 of the assembly, then try deserialize with v1.2.0.0 (updating the AssemblyInfo.cs) of the assembly, I would get a deserialization exception. However, it deserializes successfully.</p>
  
  <p>Am I missing something?</p>
  
  <p>I am serializing to file using the following:</p>
  
  <pre><code>                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();
                  }
  </code></pre>
  
  <p>and then deserializing using the following:</p>
  
  <pre><code>                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();
                  }
  </code></pre>
  
  <p>I've also noticed that the serialized file produced using FormatterAssemblyStyle.Full and FormatterAssemblyStyle.Simple both contain the complete version info (e.g. Version 1.0.0.0 Culture = neutral, PublicKeyToken = null) - I thought that Simple would not add all this information? (see formatters and assembly names section from <a href="http://www.diranieh.com/NETSerialization/BinarySerialization.htm#MySerializableClass" rel="nofollow noreferrer">this</a>)</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>The only difference I have seen so far is, if I use Simple, then I <em>don't</em> have to place the <code>OptionalField</code> attribute to new fields in a serialized class for it to de-serialize old versions successfully. If I use Full, then it does throw an exception unless I place the <code>OptionalField</code> attribute on new fields. Is this the only difference if using assemblies which are not strong named??</p>
  
  <p>See <a href="https://stackoverflow.com/questions/3634823/have-optionalfield-been-obsoleted-in-c">this</a> for details.</p>
  
  <p>Thanks in advance</p>