title: Bug in the File.ReadLines(..) method of the .net framework 4.0
body: <p>This code :</p>
  
  <pre><code>IEnumerable&lt;string&gt; lines = File.ReadLines("file path");
  foreach (var line in lines)
  {
      Console.WriteLine(line); 
  }
  foreach (var line in lines)
  { 
      Console.WriteLine(line); 
  } 
  </code></pre>
  
  <p>throws an <code>ObjectDisposedException : {"Cannot read from a closed TextReader."}</code> if the second <code>foreach</code> is executed. 
  It seems that the iterator object returned from <code>File.ReadLines(..)</code> can't be enumerated more than once. You have to obtain a new iterator object by calling <code>File.ReadLines(..)</code> and then use it to iterate.</p>
  
  <p>If I replace <code>File.ReadLines(..)</code> with my version(parameters are not verified, it's just an example):</p>
  
  <pre><code>public static IEnumerable&lt;string&gt; MyReadLines(string path)
  {
      using (var stream = new TextReader(path))
      {
          string line;
          while ((line = stream.ReadLine()) != null)
          {
              yield return line;
          }
      }
  }
  </code></pre>
  
  <p>it's possible to iterate more than once the lines of the file.</p>
  
  <p>An investigation using <code>.Net Reflector</code> showed that the implementation of the <code>File.ReadLines(..)</code> calls a private <code>File.InternalReadLines(TextReader reader)</code> that creates the actual iterator. The reader passed as a parameter is used in the <code>MoveNext()</code> method of the iterator to get the lines of the file and is disposed when we reach the end of the file.  This means that once <code>MoveNext()</code> returns false there is no way to iterate a second time because the reader is closed and you have to get a new reader by creating a new iterator with the <code>ReadLines(..)</code> method.In my version a new reader is created in the <code>MoveNext()</code> method each time we start a new iteration.</p>
  
  <p>Is this the expected behavior of the <code>File.ReadLines(..)</code> method?</p>
  
  <p>I find troubling the fact that it's necessary to call the method each time before you enumerate the results. You would also have to call the method each time before you iterate the results of a Linq query that uses the method.</p>