Error: Unable to evaluate expression because the code is optimized

柔情痞子 提交于 2019-12-08 15:16:54

问题


I am getting an error in my asp.net app that reads

"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

protected void btnCustomerProfile_Click(object sender, EventArgs e)
{
    try
    {
        Server.Transfer("CustomerProfile.aspx");
    }
    catch (Exception ex)
    {
        Response.Write(ex.ToString());
    }
    finally
    { }
}

After searching SO, I see most of the similar posts involve response.redirect. My code is using server.transfer and my application is also using Master Pages.

How can I resolve this issue?

Update: For some reason, this error occurs is I use Response.Redirect as well. Unfortunately I cannot use Server.Execute, because Server.Execute calls the calling page towards the end.


回答1:


You will get an error, but the code block below will trap it and you can get on with your life.

Try this:

using System.Threading.ThreadAbortException;

catch(ThreadAbortException ex)
{
    throw;
}



回答2:


The issue you describe seems to be by design as shown here:

http://support.microsoft.com/kb/312629/EN-US/

Using Server.Execute should solve the problem




回答3:


Have you tried replacing the server.transfer with response.redirect()?

Server.Transfer VS Response.Redirect




回答4:


I faced this message when I was testing working of multi-threading application using MS-Test.

I found the reason for this was because the testing main thread got ended and initialized cleaning of objects while other created threads which are meant to run infinitely were still working.

As teat clean up method kills objects these threads gets aborted showing above message.



来源:https://stackoverflow.com/questions/10982949/error-unable-to-evaluate-expression-because-the-code-is-optimized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!