title: ASP.Net Download file to client browser
body: <p>I'm writing a simple test page to download a text file from a browser on button click.  I am getting a really strange error that I have never seen before.  Any thoughts?</p>
  
  <p>The error occurs on <code>Response.End();</code> and the file never gets to the client browser</p>
  
  <p>Code:</p>
  
  <pre><code>  string filePath = "C:\\test.txt";
    FileInfo file = new FileInfo(filePath);
    if (file.Exists)
    {
      Response.ClearContent();
      Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
      Response.AddHeader("Content-Length", file.Length.ToString());
      Response.ContentType = "text/plain";
      Response.TransmitFile(file.FullName);
      Response.End();
    }
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.</p>
  </blockquote>