Service Unavailable
I hit a bizarre error today - one of those where ASP.NET hinders, not helps. But surprisingly it's quite common and well documented. It starts with browsing your site and hitting a "Service Unavailable". This is quite a scary message since I have Application_Error logging stuff, IIS handling 500's and many other ways to stop errors become catastrophic.
So this is serious. Luckily, it's on a staging site and most people are OOF so there's just me and well, the bosses, looking at this. Mmmm, maybe it is serious!
So Rob our IT guy sends me this from the event log:
Event Type: Error
Event Source: .NET Runtime 2.0 Error Reporting
Event Category: None
Event ID: 5000
Date: 11/30/2006
Time: 1:31:02 PM
User: N/A
Computer: DALSTG001
Description:
EventType clr20r3, P1 w3wp.exe, P2 6.0.3790.1830, P3 42435be1, P4 system.web, P5 2.0.0.0, P6 45063b0f, P7 576, P8 41, P9 exception, P10 NIL.
Yep, that's it. No stack trace.No assembly name even. Just *poof*, bye bye.
The web site at this point has died, and I'm getting muttering from the IT dept who immediately put me in my own app pool. (non-geek: that's like the dunces hat, sit in the corner).
But like I said, luckily Google is full of this error.
It turns out that ASP.NET changed it's behavior between 1.1 and 2.0. Now, Unhandled exceptions cause ASP.NET-based applications to unexpectedly quit in the .NET Framework 2.0. Not exceptions that you allow to bubble out to Application_Error etc, no.
Exceptions that happen in other threads, not associated with a request.
Kinda sucky, but I get the reason it was changed - it was more sucky before when potentially thousands of exceptions were just ignored. Personally I think MSFT could have done a better job at logging just a tad more information about the error, but their KB gives you all the code you need to install a new HttpModule that will log the info for you.
Peter Bromberg even zips up a working solution for you. What do you want? Me to come to your house and do the washing up too?
FWIW, I ignored all that about strong naming, GAC, etc. I just dropped my dll into the bin and set my web.config:
<httpModules>
<add name="UnhandledExceptionModule" type="WebMonitor.UnhandledExceptionModule, UnhandledExceptionModule, Version=1.0.0.0"/>
</httpModules>
And lo and behold it worked first time. More data was logged, and within seconds I realized the culprit was me of course. Well, sort of anyway. I use Dave Wanta's amazing aspNetEmail component and by default I set it to send emails in the background to make the web app more responsive when dealing with slug mail servers. A very clever component this.
I simply made it the default on all Dozing Dog CMS installations because it always worked perfectly. I didn't see a downside until today, when I realized that my normal practice when setting up a website is to ignore the email setup initially. So, in ASP.NET 1.1, every email being sent (admin emails are sent when someone edits content for example) would generate exceptions that were lost in the ether.
Not in 2.0. Now, if you don't set your mail server up correctly you will pay dearly!
Of course, I took the easy way out and just set the mail method to "Regular". Now the errors are trapped on the regular thread and logged and ignored by me instead.
ASP.NET 3.5 Web Hosting: 3 Months FREE + FREE Setup - CLICK HERE!