ASP.NET configuration gotcha – level 200

For people starting out with ASP.NET, the appSettings node in the web.config file will be all that is necessary for storing configuration items, but when you start creating your own config section handlers and strongly-typing your configuration items, you may run into a small snag that may cost you 1/2 a day to track down.


Configuration section names (since they are xml) are case sensitive.  Xml is case sensitive.


 


I have a section:


<configSections>


<section name=”SiteMap” type=”WebTestHarness.SiteMapConfig, WebTestHarness” />


</configSections>


but if I call:



ConfigurationSettings.GetConfig(“siteMap”);


I get mysterious errors elsewhere in my code.  My config section didn’t get loaded.  It turns out that the section “siteMap” wasn’t found.  “SiteMap” is the correct name.   Of course, I expected the .GetConfig() method to throw an exception if the section wasn’t found, but it doesn’t.  It just returns nothing and lets my code keep going.


 


Now, armed with this knowledge, I will just check the return value of the method to determine if the GetConfig was successful.