title: Serialize and Deserialize object graph using BinaryFormatter
body: <p>I'm trying to serialize my object graph to a string then deserialize it from a string. The object serializes just fine if I do this </p>
  
  <pre><code>using (var memStream = new System.IO.MemoryStream())
  {
       mf.Serialize(memStream, this);
       memStream.Seek(0, 0);
  
       Search s;
       using (var memStrClone = new System.IO.MemoryStream())
       {
            memStream.CopyTo(memStrClone);
            memStrClone.Seek(0, 0);
            s = mf.Deserialize(memStrClone) as Search;
       }
  }
  </code></pre>
  
  <p>The above code works but serializing to a string and trying to deserialize that same string like this</p>
  
  <pre><code>Search s;
  string xml = ToString&lt;Search&gt;(this);
  s = FromString&lt;Search&gt;(xml);
  
  public static TType FromString&lt;TType&gt;(string input)
  {
       var byteArray = Encoding.ASCII.GetBytes(input);
       using (var stream = new MemoryStream(byteArray))
       {
            var bf = new BinaryFormatter();
            return (TType)bf.Deserialize(stream);
       }
  }
  
  public static string ToString&lt;TType&gt;(TType data)
  {
       using (var ms = new MemoryStream())
       {
            var bf = new BinaryFormatter();
            bf.Serialize(ms, data);
            return Encoding.ASCII.GetString(ms.GetBuffer());
       }
  }
  </code></pre>
  
  <p>Throws an exception </p>
  
  <blockquote>
    <p><em>No assembly ID for object type '1936026741 Core.Sebring.BusinessObjects.Search.Search'.</em></p>
  </blockquote>
  
  <p>Any help is greatly appreciated. Thanks.</p>