title: Cannot access a closed Stream when returning FileStreamResult from C# .NetCore API
body: <p>C# .Net-Core 3.1 </p>
  
  <p>In my C# api I am returning a pdf file in a FileStreamResult, works great.</p>
  
  <p>Generally I wrap streams in using, however this code fails with 
  <code>Cannot access a closed Stream</code>.</p>
  
  <pre><code>using (MemoryStream stream = new MemoryStream(byteArray))
  {
      fileStreamResult = new FileStreamResult(stream, "application/pdf");
  }
  return (ActionResult)fileStreamResult;
  </code></pre>
  
  <p>So I need to do this:</p>
  
  <pre><code>var stream = new MemoryStream(byteArray);
  fileStreamResult = new FileStreamResult(stream, "application/pdf");
  return (ActionResult)fileStreamResult;
  </code></pre>
  
  <p>I'm assuming the stream needs to remain open, should I be concerned about memory leaks or does IIS close the stream? Are there better alternatives?</p>