Thursday, March 3, 2011

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

Suddenly I am getting the error "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack" from my asp.net application. After spending sometimes online, I found the following cause and solution for the error. Hope the solution might help you, if you are facing the same problem.

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

Cause: If you use either Response.Redirect or Server.Transfer method, you may face this problem. I was calling Response.Redirect method inside the Try...Catch block. This happens because both methods call Response.End internally.

Solution: Pass "false" to endResponse parameter of Response.Redirect method

Response.Redirect ("xyz.aspx", false);

Thats it. Simple.

Happy programming!

1 comment:

Anonymous said...

Perfect solution, simple and it work like a charm, thanks for posting!!