title: Serialize HashTable to string and back
body: <p>I am trying to serialize a Hashtable into a string and then back into a hash table but my code for deserializing keeps failing.</p>
  
  <p>To Deserialize:</p>
  
  <pre><code>byte[] bytes = System.Text.Encoding.Unicode.GetBytes(hash.value);
  System.IO.MemoryStream ms = new System.IO.MemoryStream();
  ms.Write (bytes,0,bytes.Length);
  ms.Seek(0,System.IO.SeekOrigin.Begin);
  
  System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  Hashtable h = (Hashtable)bf.Deserialize(ms);
  </code></pre>
  
  <p>To Serialize:</p>
  
  <pre><code>MemoryStream ms = new MemoryStream();
  System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
  bf.Serialize(ms, hash);
  byte[] bt = ms.ToArray();
  this.value=System.Text.Encoding.Unicode.GetString(bt);
  </code></pre>
  
  <p>This is the error I am getting with the above code:
  <code>EndOfStreamException: Failed to read past end of stream.</code></p>
  
  <p>But if anyone has a more efficient way to do this I am all ears.</p>