title: Why might ReadToEnd throw an OutOfMemory exception but ReadAllText doesn't?
body: <p>I'm running into an issue where ReadToEnd is throwing an OutOfMemory exception when trying to read a 16MB text file in an ASP.net website.</p>
  
  <p>While investigating the cause I came across File.ReadAllText which is really what I'm doing, I don't care about how I get the text.</p>
  
  <p>But looking at the documentation of <a href="http://msdn.microsoft.com/en-us/library/ms143368(v=VS.90).aspx" rel="nofollow">ReadAllText</a> it doesn't mention the possibility of an OutOfMemory exception. Why is that? Is it implemented differently than ReadToEnd in such a way that its less likely to run out of memory, or does it throw some other exception if it runs out of memory?</p>
  
  <p><strong>Edit</strong> Adding code just to show what I'm currently doing:</p>
  
  <pre><code>StreamReader inputFile = System.IO.File.OpenText(filename);
  string cacheData = inputFile.ReadToEnd();
  inputFile.Close();
  </code></pre>
  
  <p>And sometimes I get OutOfMemory exception on line 2. No parsing going on, the file is only 16M of text, nothing strange that I know of.</p>
  
  <p>Restarting IIS generally fixes it. But I have like 2G of RAM free when I get the error, IIS maybe hitting some internal limit? The w3wp.exe process usually uses 350-500M (This is IIS 6 on Windows Server 2003)</p>