title: C# ConfigurationManager.GetSection could not load file or assembly
body: <p>I am stuck!  this seems really daft but I can not see where I am going wrong.  I am creating a 2.0 C# ASP.NET website.  I am trying to use a custom section in the web.config file with:</p>
  
  <pre><code>DatabaseFactorySectionHandler sectionHandler = ConfigurationManager.GetSection("DatabaseFactoryConfiguration") as DatabaseFactorySectionHandler;
  </code></pre>
  
  <p>I have a separate DLL for the Objects which are in Bailey.DataLayer namespace.  But when I run the test.aspx page I get the following error:</p>
  
  <pre><code>System.Configuration.ConfigurationErrorsException was unhandled by user code
  
  Message="An error occurred creating the configuration section handler for DatabaseFactoryConfiguration: Could not load file or assembly 'Bailey.DataLayer' or one of its dependencies. The system cannot find the file specified. (C:\\Documents and Settings\\Administrator.PIP\\My Documents\\Visual Studio 2005\\WebSites\\bailey\\web.config line 13)"
  Source="System.Configuration"
  </code></pre>
  
  <p>The class that I am trying to get is as follows:</p>
  
  <pre><code>namespace Bailey.DataLayer
  {
      public sealed class DatabaseFactorySectionHandler : ConfigurationSection
      {
          [ConfigurationProperty("Name")]
          public string Name
          {
              get { return (string)base["Name"]; }
          }
  
          [ConfigurationProperty("ConnectionStringName")]
          public string ConnectionStringName
          {
              get { return (string)base["ConnectionStringName"]; }
          }
  
          public string ConnectionString
          {
              get
              {
                  try
                  {
                      return ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
                  }
                  catch (Exception excep)
                  {
                      throw new Exception("Connection string " + ConnectionStringName +
                                          " was not found in web.config. " + 
                                          excep.Message);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>The web config file has this section:</p>
  
  <pre><code>&lt;configSections&gt;
    &lt;section name="DatabaseFactoryConfiguration" 
             type="Bailey.DataLayer.DatabaseFactorySectionHandler, Bailey.DataLayer" /&gt;
  &lt;/configSections&gt;
  </code></pre>
  
  <p>I have done this in a console app without a problem but can not see any differences apart from it being in a web page.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It all compiles and throws the error at runtime so I can only assume it find the assembly because it is referenced in the test.aspx.cs page.</p>
  
  <p>I have the following using statement at the top of the test.aspx.cs page:</p>
  
  <pre><code>using Bailey.DataLayer;
  </code></pre>
  
  <p>Here is the whole web.config file so there is no confusion:</p>
  
  <pre><code>&lt;configuration&gt;
     &lt;configSections&gt;
        &lt;section name="DatabaseFactoryConfiguration" type="Bailey.DataLayer.DatabaseFactorySectionHandler, Bailey.DataLayer" /&gt;
     &lt;/configSections&gt;
      &lt;appSettings/&gt;
     &lt;connectionStrings&gt;
        &lt;add name="BaileyMDFConString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bailey.mdf;Integrated Security=True;User Instance=True"  providerName="System.Data.SqlClient" /&gt;
      &lt;/connectionStrings&gt;
       &lt;DatabaseFactoryConfiguration Name="System.Data.SqlClient" ConnectionStringName="BaileyMDFConString" /&gt;
     &lt;system.web&gt;         
        &lt;compilation debug="true"/&gt;       
        &lt;authentication mode="Windows"/&gt;  
     &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>