title: Deserialization not working on MemoryStream
body: <pre><code>//Serialize the Object
  MemoryStream ms = new MemoryStream();
  IFormatter formatter = new BinaryFormatter();
  formatter.Serialize(ms , ObjectToSerialize);
  byte[] arrbyte = new byte[ms .Length];
  ms.Read(arrbyte , 0, (int)ms .Length);
  ms.Close();
  
  //Deserialize the Object
  Stream s = new MemoryStream(arrbyte);
  s.Position = 0;
  Object obj = formatter.Deserialize(s);//Throws an Exception
  s.Close();
  </code></pre>
  
  <p>If I try to Deserialize with the above way it gives the Exception as </p>
  
  <p>'Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.'</p>
  
  <p>Where below code is working</p>
  
  <pre><code>//Serialize the Object
  IFormatter formatter = new BinaryFormatter();
  MemoryStream ms = new MemoryStream();
  formatter.Serialize(ms, ObjectToSerialize);
  ms.Seek(0, SeekOrigin.Begin);
  byte[] arrbyte = ms.ToArray();
  
  //Deserialize the Object
  Stream s= new MemoryStream(byt);
  stream1.Position = 0;
  Object obj = formatter.Deserialize(s);
  stream1.Close();
  </code></pre>
  
  <p>The only difference is the first approach uses the Read method to populate the byte array where as the second one uses the Seek &amp; ToArray() to populate the byte array.
  What is the reason for the Exception.</p>