Featured Post

Speaking at CodeStock and Deep Fried Bytes Live!

  Last year I was invited to speak at a lot of conferences and code camps but the one that I didn’t get to go to due to scheduling conflicts was CodeStock held in Knoxville, TN.  This year I made sure it was on my schedule because the majority of my Twitterverse / Tribe will be there and I couldn’t...

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