Skip to content


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

Related Posts

  1. _CGRectZero Error with UITableViewCell Preface If you haven’t agreed to the iPhone SDK License Agreement and NDA, please ignore this post, or Apple might hunt you down with their lawyers… and what a horrible death that would be. Problem I keep getting a build error when trying to subclass the UITableViewCell Solution Add the...
  2. MS SQL 2005 (T-SQL) Row Count for Each Table At work I needed a solution to give me a count of how many rows each table contained. I've always liked phpMyAdmin's ability to list all the tables and show their size and row count. I've found it immensely helpful. However, I couldn't find anything similar for SQL Server Manager...
  3. PHP Singletons, Sub-Classing, and HAS-A Relationships I've been very busy these last fews weeks and have neglected making any posts. While there are a variety of subjects I'd love to post about, they'll most likely have to wait until the next year. However, I thought I might be able to throw up a quick example of...
  4. PHP Article: 10 Principles of the PHP Masters This article has some great overall advice. My only disappointment is that #10 isn't higher on the list: The single most important thing I tell people who use PHP is to turn error reporting to its maximum level. Why would I want to do this? Generally the error reporting...
  5. ASP .NET 2.0, GridViews, HyperLinkField, and JavaScript I've found some interesting notes on ASP .NET's GridView, it's limitations and work arounds. For work I was looking for a way to execute JavaScript from clicking a link on a GridView Cell. An example would be to having a list of transactions and wanting to click a link to...

Posted in Programming. Tagged with , , .

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Pooja said

    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

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.

Powered by WP Hashcash