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

5 thoughts on “ASP .NET & System.Threading.ThreadAbortException Error

  1. Hey Justin,

    Saved me getting into a vicious circle. I have finished working on my website and it is getting ready to go to production and guess what I discover this issue. My problem is exactly as yours redirecting from inside a try block. Thanks a ton.

    Regards

    Like

  2. Thanx it helped me too

    Like

  3. thank u u helped me also

    Like

  4. thanks By Justin Carmony . good nice post.

    Like

  5. Thank you. I was scratching my head at this error!

    Like

Leave a Reply to edius dersleri Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close