All writing

ASP .NET & System.Threading.ThreadAbortException Error

While doing some work today I started to run into a ThreadAbortException error. While debugging it spit back this error:

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

I was really confused because everything seemed to be working just fine, then I found this forum thread. Turns out there are several causes for this error, but mine was caused by doing a Response.Redirect(); from within a Try-Catch statement. Apparently ASP .NET does not like that.

Workaround

In a try-catch statement, use a boolean variable to mark weather or not to Redirect (or some other variable to accomplish your logic) and preform the Response.Redirect(); outside of your Try Catch. On a side note, I’ve successfully been able to Redirect from inside the Catch {} aspect, just not the try {}.

Resources

Here is the link to the forums that I found my answer:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=268544&SiteID=1

Sheet
A-3 · Detail
Drawn
Utah
Scale
1:1
Rev
2026