ASP.NET 2.0, Unhandled Exceptions and Lucene.net

Posted on April 27th, 2006.

Just saw this post from Tess about unhandled exceptions in ASP.NET 2.0. Great post by the way, with lot of useful information (as always) about using windbg and logging unhandled exceptions.
I really needed that information a month ago when I encountered the exact same problem (exception in a finalizer) with an ASP.NET web service that crashed after being idle for a while.

Fortunately for me, since the error occurred after the web application has been idle I realized it happens when the application is shut down so I attached Visual Studio to the w3wp process and did an iisreset. The debugger then stopped at the offending line.

In case you’re curios why Lucene.net was mentioned in the subject, well, it’s because the bug was in Lucene. How do you fix this error? simple:
Open the SegmentReader.cs and TermInfosReader.cs files and search for the finalizer of the classes declared there (simply search for ~), both those classes contains calls to

System.Threading.Thread.SetData(.., null);

comment the above line (actually you can remove the finalizer all together as that’s the only thing it does) and that’s it. This line was ported from the Java version of Lucene.net where this line was added to work around a bug in pre-1.4.2 JVMs. This patch is not needed in .net.

If you’re using ASP.NET 1.1/1.0 then you didn’t encounter this bug since the framework swallows these exception (see Tess’s post for more info). 

Technorati: , , ,

Make a Comment

3 Responses to “ASP.NET 2.0, Unhandled Exceptions and Lucene.net”

RSS Feed for Eyal’s Posts Comments RSS Feed

You could have just asked me and I would have told you some of the tips Tess gave 😉

Eran Sandler
April 30th, 2006

Well, First – it’s been a while since we met! We have to resurrect the pub meetings.
Second – the problem with Tips is that you have to ask the right questions. I wasn’t aware of some of the things tess mentioned so I didn’t even bother to ask.

Eyal Post
April 30th, 2006

I’m sure the next week we will have a pub meeting. These memorial days kept on falling on Monday 🙂

Eran Sandler
May 1st, 2006

Where's The Comment Form?

eXTReMe Tracker