title: Deserialize types moved across assemblies
body: <p>I have a bunch of types which have been moved from one assembly to another. I am trying to <em>deserialize</em> data which was serialized using the old assembly into types in the new assembly by using a <em>SerializationBinder</em>. </p>
  
  <p><strong>EDIT:</strong> Root namespace of the assembly is same as the assembly name. The old assembly does not exist anymore.</p>
  
  <pre><code>sealed class TypeMapBinder : SerializationBinder
      {
          public override Type BindToType( string assemblyName, string typeName )
          {
              Type typeToDeserialize = null;
  
              if ( assemblyName.Contains( "old namespace" ) )
                  typeToDeserialize = Type.GetType( typeName.Replace( "old namespace", "new namespace" ) );
              else
                  typeToDeserialize = Type.GetType( String.Concat( typeName, ", ", assemblyName ) );
  
              return typeToDeserialize;
          }
      }
  </code></pre>
  
  <p>deserialization code looks something like this -</p>
  
  <pre><code>using ( MemoryStream ms = new MemoryStream( byteArr ) )             {
                  BinaryFormatter formatter = new BinaryFormatter( );
                  formatter.Binder = new TypeMapBinder( );
                  return formatter.Deserialize( ms );             
  }
  </code></pre>
  
  <p>When i try to deserialize i get an error where its trying to load the old assembly.</p>
  
  <blockquote>
    <p>Could not load file or assembly 'old assembly' or one of its
    dependencies. The system cannot find the file specified.</p>
  </blockquote>