Tuesday, October 4, 2011

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

I got the error "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack" in a Response.Redirect(" http://www.sharepointdotnet.com/ "). My code is in try catch block as below.
try
{
Response.Redirect("http://www.sharepointdotnet.com/ ");
}
catch (Exception ex)
{
//I am getting the exception here.
}
Cause:
Because Response.Redirect("Ur URL") usually internally calls the Response.End() and this internally calls the Thread.Abort() which internally tells the stack to end the thread.

Resolve:
To resolve this error you can put the Response.Redirect("http://www.onlysharepoint2010.com"); outside the try catch block. But since I need the statement to be inside the try catch block I have done some modifications as like below:
try
{
Response.Redirect("http://www.sharepointdotnet.com/ ",false);
}
catch (Exception ex)
{
}

No comments:

Post a Comment