Problem

If you’re working in ASP.NET and ever ran into the error:

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

You’ll probably find that the stack trace gives you no useful information as to where the error actually occurred.

The Solution

For Response.Redirect, use the overload function (Response.Redirect(String url, bool endResponse)) and pass false into the EndResponse parameter:

[csharp]Response.Redirect ("nextpage.aspx", false);[/csharp]

For Response.End, you’ll need to call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.

Details

The error occurs when you use Response.End, Response.Redirect, or Response.Transfer.The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application’s event pipeline. The line of code that follows Response.End is not executed. This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.

How to Prevent Raspberry Pi Zero from Blanking or Sleeping How to Fix ‘Converter Failed to Save File’ with Excel 2016
View Comments
There are currently no comments.