title: How to ensure that StreamReader.BaseStream.Length will return the correct value?
body: <p>I have a loop which compares the <code>BaseStream.Length</code> with the <code>lastMaxOffset</code> and let's say that 9 out of 10 times runs properly.
  <br>But it's this 1 time that BaseStream.Length somehow sets equal to 0 - in debug mode it shows normal value, always greater than 0 - and this causes an issue to my console app.
  I verified that the length is NOT equal to 0 since it's a logfile which ONLY grows. So I guess this is a BaseStream issue (maybe temporarily hasn't the length value, so it sets it to 0)
  Is there a way to ensure that <code>StreamReader.BaseStream.Length</code> will return ONLY the correct value? </p>
  
  <pre><code>using (StreamReader reader = new StreamReader(
      new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), 
      Encoding.Default))
  {
      long lastMaxOffset = this.getMaxOffsetForFile(path);
      if ( lastMaxOffset == 0 )
      {
          lastMaxOffset = this.setMaxOffsetForFile(path, reader.BaseStream.Length);
      }
  
      reader.DiscardBufferedData();
      long fileLength = reader.BaseStream.Length;
  
      if (fileLength &gt; lastMaxOffset)
      { 
           //my code 
      }
  }
  </code></pre>