title: Xml serializing and deserializing with memory stream
body: <p>I'm getting an error with the following code where it can't find a root element when it tries to deserialize the code:</p>
  
  <blockquote>
    <p>An exception of type 'System.InvalidOperationException' occurred in System.Xml.dll but was not handled in user code<br>
    Additional information: There is an error in XML document (0, 0).<br>
    Inner exception: {"Root element is missing."}</p>
  </blockquote>
  
  <p>It seems straightforward enough code, but googling and searching SO on the issue hasn't yielded any clear answers--only similar issues that are nonetheless that the answer don't help... or I'm misunderstanding something.</p>
  
  <pre><code>    [TestMethod]
      public void TestSerialize()
      {
          XmlSerializer serializer = new XmlSerializer(testObject.GetType());
          MemoryStream memStream = new MemoryStream();
          serializer.Serialize(memStream, testObject);
  
          XmlSerializer xmlSerializer = new XmlSerializer(testObject.GetType());
          TestObject testObj = ((TestObject)xmlSerializer.Deserialize(memStream));
          assert(testObject == testObj);
      }
  
  public class TestObject
  {
      public int IntProp { get; set; }
      public string StringProp { get; set; }
  }
  </code></pre>
  
  <p>The alleged duplicate question at <a href="https://stackoverflow.com/questions/10125810/root-element-is-missing">Root element is missing</a> uses XMLDocument objects and has a different correct answer.</p>