title: How to return a Stream from a method, knowing it should be disposed?
body: <p>I have a method that takes FileStream as input. This method is running inside a for loop.</p>
  
  <pre><code>private void UploadFile(FileStream fileStream)
  {
      var stream = GetFileStream();
      // do things with stream
  }
  </code></pre>
  
  <p>I have another method which creates and returns the FileStream:</p>
  
  <pre><code>private FileStream GetFileStream()
  {
      using(FileStream fileStream = File.Open(myFile, FileMode.Open))
      {
          //Do something
          return fileStream;
      }
  }
  </code></pre>
  
  <p>Now the first method throws an <code>ObjectDisposedException</code> when I try to access the returned FileStream, probably because it is already closed since I am using "<code>using</code>" to properly dispose the stream.</p>
  
  <p>If I don't use "using" and instead use it as follows, then the FileStream remains open and the next iteration of the loop (operating on the same file) throws an exception telling the file is already in use:</p>
  
  <pre><code>private FileStream GetFileStream()
  {
      FileStream fileStream = File.Open(myFile, FileMode.Open);
      //Do something
      return fileStream;
  }
  </code></pre>
  
  <p>If I use a try-finally block, where I close the stream in the <code>finally</code> then it also throws the <code>ObjectDisposedException</code>.</p>
  
  <p>How to effectively return file stream and close it?</p>