Mark Gilbert's Blog

Science and technology, served light and fluffy.

Back off, I need my space! Invalid web.config and the Yellow Screen of Death

TheSetup

This past week I was reformatting a web.config file to clean up the whitespace.  Several sections of the file started out looking like this:

<httpHandlers>
  <remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" 
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add verb="*" path="*_AppService.axd" validate="false" 
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
     <add verb="GET,HEAD" path="ScriptResource.axd"
  type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/></httpHandlers>


Which I cleaned up to look like this:

<httpHandlers>
  <remove verb="*" path="*.asmx"/>
  <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>


This was just one section. Imagine several sections like this, all mashed up next to each other.  This may seem like Mark has gone off into OCD-wonderland, but the minutes that I spent reworking the file up front will be paid back fifty-fold throughout the life of the project.  The largest gains come when I need to add something to the file (like an appSettings value).  Since I maintain multiple versions of the web.config – one for each environment that the site will run in, such as development, staging, and production – having all of those files formatted the same, clean way allows me to quickly see when I’ve missed adding that new value to one of them.  That alone can save hours of painful troubleshooting later.

 

TheProblem

I got the files reformatted and committed them.  The build server took over and moved my changes up to the development server.  I hit the site with my browser, and was greeted with a wonderfully generic Yellow Screen of Death (YSOD).

That’s odd.  I modified the web.config for Development to turn customErrors off, and hit the site again.  Same result.

I was using ELMAH, so I checked the log folder.  Nothing.  I also had it configured to email me when an unhandled exception occurred.  My inbox was empty.

What the?  How is this error avoiding all of my attempts to report it?

I then logged into the Development web server, and opened up the properties for the site in IIS.  I remembered that the ASP.NET tab there has an “Edit Configuration” button that will open the web.config for the site.  I wanted to see what exactly IIS was saying existed in that file.  I clicked the button and got this:

Web.config error

Custom errors made have been turned off, but thankfully the light finally turned on.  I must have a syntax error in my web.config, and so the site isn’t really getting a chance to start up (which is why ELMAH wasn’t catching any of these).

 

TheSolution

I opened the web.config and sure enough, line 141 had something like this:

<add verb="*" path="*.asmx" validate="false"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

In my zeal to reformat the file, I left out a space before the “type” attribute.  I added that back in and the site came right up.

On a hunch I copied the file as web.xml, took out the space again, and tried to open it in Internet Explorer (on my system, the .xml extension has IE defined as the default application).  IE works pretty well as a quick and dirty XML validator and this case was no exception.  It also choked on the same line in the file.

 

TheMoral

So, now I have another step in my web application troubleshooting regimen.  If you’re making changes to the web.config and nothing seems to be clearing the YSOD, make sure the former is a valid XML file to begin with.

Advertisements

November 13, 2010 - Posted by | Visual Studio/.NET

Sorry, the comment form is closed at this time.

%d bloggers like this: