title: C# serializing/deserializing with memory stream System.OutOfMemoryException
body: <p>I am trying to serialize/de-serialize a stream of around 50MB xml data with the following code and I get System.OutOfMemoryException exception.</p>
  
  <pre><code>   var formatter = new BinaryFormatter();
          var stream = new MemoryStream();
          using (stream)
          {
              formatter.Serialize(stream, source);
              stream.Seek(0, SeekOrigin.Begin);
              return (T) formatter.Deserialize(stream);
          }
  </code></pre>
  
  <p>I debugged the code and it throws OutOfMemoryException exception on the formatter.Serialize(stream,source) line.</p>
  
  <p>I did some search in it says that limit is 2GB. How can I debug to find out the reason or is there any efficent way of writing this code? Or any tool to watch the memory usage.</p>
  
  <p>Thanks,</p>