【问题标题】:InnerException = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack [closed]InnerException =无法评估表达式,因为代码已优化或本机框架位于调用堆栈顶部[关闭]
【发布时间】:2013-10-07 07:21:30
【问题描述】:

我的代码是

请给我解决方案...谢谢

  bool b = false;
  string str=Server.MapPath("~/Files/"+filepath);


      //  Send the file to the browser
      Response.AddHeader("Content-type", filetype);
      Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

      Response.TransmitFile(Server.MapPath("~/Files/" + filepath));


      Response.Flush();
      //  HttpContext.Current.ApplicationInstance.CompleteRequest();
       Response.End();

      b = true;

【问题讨论】:

  • 外部异常是什么?如果我们不知道实际问题是什么,我们就无法回答。内部异常无关紧要。
  • 您是否在代码中重定向?
  • 外部异常是 --- 线程被中止。

标签: c# asp.net entity-framework


【解决方案1】:

此通知表示线程当前正在执行代码,因此不能用于计算表达式。

使用

 HttpContext.Current.ApplicationInstance.CompleteRequest 

而不是Response.End();

Response.Flush 和 Response.End 做同样的事情,除了 Response.End 停止执行页面并引发 EndRequest 事件。

当当前响应提前结束时,调用End 方法会引发ThreadAbortException 异常。

【讨论】:

  • 谢谢!我们遇到了 Unable to evaluate expression 错误,这个答案挽救了我们的一天!
  • @JPMarichal 我很高兴这有帮助。
【解决方案2】:

所以我在使用异步触发按钮时遇到了同样的问题

<asp:AsyncPostBackTrigger ControlID="btn_login" />

在更新面板中。我改用常规回帖不是最好的,但它起作用了。

<asp:PostBackTrigger ControlID="btn_login" />. 

因为我只是在页面上重定向,所以这是一个可行的解决方案。

【讨论】:

    【解决方案3】:

    也许是因为 Response.End 给出了线程中止错误?看 http://msdn.microsoft.com/en-us/library/system.web.httpresponse.end.aspx

    【讨论】:

      猜你喜欢
      • 2012-07-11
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多