title: Unable to evaluate expression... on web page
body: <p>Related to this question:  <a href="https://stackoverflow.com/questions/2041482/unable-to-evaluate-expression-because-the-code-is-optimized-or-a-native-frame-is">Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack</a></p>
  
  <p>I am currently seeing this in my exception: </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>
  
  <p>Here's the offending code.  The exception is thrown on response.End();</p>
  
  <pre><code>DataSet dataSet = new DataSet();
  dataSet.Tables.Add(table); 
  // Table is a well-formatted DataTable formed from data stored in a Session variable
  
  HttpResponse response = HttpContext.Current.Response;
  response.Clear();
  response.Charset = "";
  
  
  response.ContentType = "application/vnd.ms-excel";
  response.AddHeader("Content-Disposition", "attachment;filename=\"ExcelFile.xls\"");
  
  
  using (StringWriter stringWriter = new StringWriter())
  using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter))
  {
      DataGrid dataGrid = new DataGrid { DataSource = dataSet.Tables[0] };
  
      dataGrid.DataBind();
      dataGrid.RenderControl(htmlTextWriter);
  
      response.Write(stringWriter.ToString());
      response.End();
  }
  </code></pre>
  
  <p>This code is being used in an "export to excel" button on a web page.  This is copied directly from another page that uses the same functionality that works correctly.</p>
  
  <p>Any ideas on how to debug this issue?  How can I get to a point where I can see the exception?  Also, how does the related question apply here?  The top answer and selected answers are incredibly vague.</p>
  
  <p>Please note that the data in <code>table</code> is stored in Session state.</p>
  
  <p>Thanks in advance.</p>