title: C# XSLT Transformation Out of Memory
body: <p>All, </p>
  
  <p>I have the below code for Transforming an XML Document using an XSLT.
  The problem is when the XML Document is around 12MB the C# runs out of memory.
  Is there a different way of doing the transform without consuming that much memory?</p>
  
  <pre><code>public string Transform(XPathDocument myXPathDoc, XslCompiledTransform myXslTrans)
      {
          try
          {
              var stm = new MemoryStream();
              myXslTrans.Transform(myXPathDoc, null, stm);
              var sr = new StreamReader(stm);
              return sr.ReadToEnd();
          }
          catch (Exception e)
          {
            //Log the Exception
          }
      }
  </code></pre>
  
  <p>Here is the stack trace:</p>
  
  <pre><code>at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32       length, Int32 capacity)
  at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)   
  at System.Text.StringBuilder.Append(Char[] value, Int32 startIndex, Int32 charCount)
  at System.IO.StreamReader.ReadToEnd()
  at Transform(XPathDocument myXPathDoc, XslCompiledTransform myXslTrans)
  </code></pre>