Featured Post

Speaking Engagements For April – May 2007

For the next several weeks or month I’ve got several events lined up I’ll be speaking at in different parts of the country.  If you are in these areas I hope you can stop in and say hi. Where:  http://www.alabamacodecamp.com  (Alabama Code Camp)When: April 14th, 2007City:  Mobile, AL Last...

Read More


Custom ConfigurationSection Error: Unable to load type

Posted by Keith Elder | Posted in .Net | Posted on 15-09-2008

I was creating a custom ConfigurationSection for an App.Config file.  Thinking I had done everything correctly (this really isn’t that hard) I kept getting this error.

“An error occurred creating the configuration section handler for LogManagerGroup/LogManager: Unable to load type ‘Core.Logging.Configuration.LogManagerSection, Core.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=br549br549br549′ because it is not public.”

I tried everything I knew to debug this thinking the problem was with the config file but it turned out to be code related.  Here’s the bad example:

   1: public class MyCustomSection : ConfigurationSection
   2: {
   3:     [ConfigurationProperty("IsDebugEnabled", DefaultValue = "true", IsRequired = true)]
   4:     public Boolean IsDebugEnabled
   5:     {
   6:         get
   7:         {
   8:             return (Boolean)this["IsDebugEnabled"];
   9:         }
  10:         set
  11:         {
  12:             this["IsDebugEnabled"] = value;
  13:         }
  14:     }
  15: }

Here’s the fix (just add a constructor):

   1: public class MyCustomSection : ConfigurationSection
   2: {
   3:     // Adding Constructor fixes this error
   4:     public MyCustomSection()
   5:     {
   6:  
   7:     }
   8:  
   9:     [ConfigurationProperty("IsDebugEnabled", DefaultValue = "true", IsRequired = true)]
  10:     public Boolean IsDebugEnabled
  11:     {
  12:         get
  13:         {
  14:             return (Boolean)this["IsDebugEnabled"];
  15:         }
  16:         set
  17:         {
  18:             this["IsDebugEnabled"] = value;
  19:         }
  20:     }
  21: }

Hopefully this will save someone time trying to figure this out.

If you are wondering “why” this is the case, it is because the ConfigurationSection class the custom section inherits from is an abstract base class that doesn’t have a default constructor therefore one has to be added. 

  • Sergey

    thank a lot! , this is save my time 

  • Anonymous

    I bet my head in a wall for an hour. Thank you very much