This project has moved. For the latest updates, please go here.

Exception when calling instance

Nov 9, 2010 at 3:19 PM

Hi,
I have used the Configuration Section Designer v1.6 to design a simple configuration section shown below:

  <configSections>
    <section name="emailConfigSection" type="EmailGenerator.EmailConfigSection"/>
  </configSections>

  <emailConfigSection>
    <emails>
      <email enabled="true" key="1" />
    </emails>
  </emailConfigSection>

I have console project (.net 3.5) with a reference to the Confiugration Section project and execute the following line:

EmailConfigSection emailConfigSection = EmailConfigSection.Instance;

When calling this line I get the following exception:

An error occurred creating the configuration section handler for emailConfigSection: Could not load type 'EmailGenerator.EmailConfigSection' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (P:\Documents\Visual Studio 2008\Projects\GenerateTestEmail\GenerateTestEmail\bin\Debug\GenerateTestEmail.vshost.exe.Config line 4)
Why do I get this error?
/David
Coordinator
Jul 14, 2011 at 2:44 PM

I know this is old, but I thought I'd chime in in case other users encounter this issue.
This exception occurs when you don't specify the assembly name in the "configSections/section" element. If you do not specify the assembly name, it will look for "EmailGenerator.EmailConfigSection" in the System.Configuration namespace.

See below for example on how to fix this:

 

  <configSections>
    <section name="emailConfigSection" type="EmailGenerator.EmailConfigSection, MyAssemblyName"/>
  </configSections>

  <emailConfigSection>
    <emails>
      <email enabled="true" key="1" />
    </emails>
  </emailConfigSection>

Jul 21, 2011 at 3:04 PM

Shouldn't the output of the project containing the .csd file be added as the default assembly name in the sample?

Coordinator
Jul 22, 2011 at 5:58 PM

In my tests, I'm getting a value for the assembly name part, but it is incorrect. Instead of getting the assembly name, I'm getting the namespace. This will be looked into.