Friday, July 25, 2008

Try Catch & System.Threading.ThreadAbortException : Unable to evaluate expression because the code is optimized or a native frame is on top of the cal

Hi,

In my asp.net application i have developed some functionality which was working fine until I added try catch block. The issue is when Response.Redirect("URL"); is getting executed there occurs System.Threading.ThreadAbortException with message "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack".

The reason for this exception is because Response.Redirect, when called with just the URL, or with the URL and a Boolean value of true, calls the Response.End method. Response.End then calls Thread.Abort on the current thread which will result in ThreadAbortException.

So the best solution is to call redirect like Response.Redirect("URL",false) or after try catch block...

Regards
Fauzi

1 comment:

asif said...

add 2nd parameter as false like as follows:

response.redirect ("abc.aspx", false)