title: System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Cannot access a closed file.'
body: <p>I am working on web API core and returning <code>IActionResult</code>. One of my API throws error while returning <code>FileResult</code>. </p>
  
  <p>I get the following error.</p>
  
  <blockquote>
    <p>System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'Cannot access a closed file.'.</p>
  </blockquote>
  
  <p>My code is something like :</p>
  
  <pre><code>FileStream zipToOpen;
  
  using (zipToOpen = new FileStream(Path.Combine(reportsPath, Guid.NewGuid().ToString()) + ".zip", FileMode.Create))
  {
      using (ZipArchive zipArchive = new ZipArchive(zipToOpen, ZipArchiveMode.Create, true))
      {
          foreach (var document in documents)
          {
              string fileName = string.Empty;
              int index = document.Path.LastIndexOf("/");
              if (index != -1)
                  fileName = document.Path.Substring(index + 1);
              zipArchive.CreateEntryFromFile(document.Path, fileName);                            
          }
      }
  
      //zipToOpen.Position = 0;
      return File(zipToOpen, "application/zip", "MyDocuments.zip");
  }
  </code></pre>
  
  <p>Can anyone please help me what's the issue.</p>