Tuesday, February 10, 2009

application unavailable

Here's a helpful tip if you're getting messages like this when you try to access an ASP.NET page you're working on:

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.



The short answer is: probably stack overflow. Check your methods and properties for infinite recursion.

Long answer:

This error is not usually very helpful, and the Event Log doesn't show anything interesting except a note that basically says something really bad happened to aspnet_wp.exe, and it exited unexpectedly. Sometimes you can't seem to pause execution in debug mode, too.

Just in case you're fuzzy on what happens normally, aspnet_wp.exe ("ASP.NET") is a chunk stuck onto IIS to serve your ASPX pages. When IIS gets a request from a web user for a file ending in .aspx, it thinks to itself, "What the heck is this?! ASP.NET, do you know anything about this?" And then aspnet_wp.exe says, "Oh sure, I do those all the time." And then IIS says, "Good-- here, take it!" So ASP.NET goes through executing your code for the page. Little does it know that it has fallen into a doomed execution path of infinite recursion that you created! It keeps looping along, until Windows sees that it has a 1.5 bizillion stack frames, and it says, "Hey you! You're taking more than your fair share, mister!" ...And Windows kills the process. Brutal, I know. Then, the .NET Runtime Error Reporting thingamajig comes along and says, "Oh my gosh! They killed ASP.NET!!" And writes that in your Event Log.

So yeah, watch out for infinite recursion. I suppose a similar problem would happen if you overflowed the heap instead.