Could not load type System.Configuration.NameValueSectionHandler

Posted on Dot net Slackers See other posts from Dot net Slackers
Published on Thu, 06 May 2010 00:00:00 GMT Indexed on 2010/05/06 18:59 UTC
Read the original article Hit count: 556

Filed under:

If you upgrade older .NET sites from 1.x to 2.x or greater, you may encounter this error when you have configuration settings that look like this:

<section name="CacheSettings" 
    type="System.Configuration.NameValueFileSectionHandler, System"/>

Once you try to run this on an upgraded appdomain, you may encounter this error:

An error occurred creating the configuration section handler for CacheSettings: Could not load type 'System.Configuration.NameValueSectionHandler' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Microsoft moved a bunch of the Configuration related classes into a separate assembly, System.Configuration, and created a new class, ConfigurationManager.  This presents its own challenges which Ive blogged about in the past if you are wondering where ConfigurationManager is located.  However, the above error is separate.

The issue in this case is that the NameValueSectionHandler is still in the System assembly, but is in the System.Configuration namespace.  This causes confusion which can be alleviated by using the following section definition:

<section name="CacheSettings" 
    type="System.Configuration.NameValueSectionHandler, 
    System, Version=2.0.0.0, Culture=neutral, 
    PublicKeyToken=b77a5c561934e089" />

(you can remove the extra line breaks within the type=)

With this in place, your web application should once more be able to load up the NameValueSectionHandler.  I do recommend using your own custom configuration section handlers instead of appSettings, and I would further suggest that you not use NamveValueSectionHandler if you can avoid it, but instead prefer a strongly typed configuration section handler.


Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.



Email this Article

© Dot net Slackers or respective owner