title: Unrecognized element exception in custom ConfigurationSection
body: <p>The problem is, as the title say I get an exception whenever I try to load a custom CustomConfiguration section from my .config file. The app.config file I try to load looks like this.</p>
  
  <pre><code>....
  &lt;configSections&gt;
      &lt;sectionGroup name="MainSection"&gt;
          ...
          &lt;section name="Directories" type="MyNamespace.DirectoriesSettings, Assembly"/&gt;
      &lt;/sectionGroup&gt;
  &lt;/configSections&gt;
  ....
  
  &lt;MainSection&gt;
      ...
      &lt;Directories Count="1"&gt;
        &lt;Directory id="1" Path="Some\Path" Working="And\Another\Path" Country="US"/&gt;
      &lt;/Directories&gt;
  
  &lt;/MainSection&gt;
  ....
  </code></pre>
  
  <p>And the code </p>
  
  <pre><code>namespace MyNamespace
  {
      internal class DirectoriesSettings : ConfigurationSection
      {
          [ConfigurationProperty("Count")]
          public int Count { get { return Convert.ToInt32(base["Count"]); } }
  
          [ConfigurationProperty("Directories", IsDefaultCollection = true, IsRequired = true)]
          [ConfigurationCollection(typeof(DirectoryElement), AddItemName = "Directory", CollectionType = ConfigurationElementCollectionType.BasicMap)]
          public DirectoryElementCollection Directories { get { return (DirectoryElementCollection)base["Directories"]; } }
  
      }
  
      internal class DirectoryElementCollection : ConfigurationElementCollection
      {        
          protected override ConfigurationElement CreateNewElement()
          {
              return new DirectoryElement();
          }
  
          protected override object GetElementKey(ConfigurationElement element)
          {
              return ((DirectoryElement)element).Id;
          }
      }
  
      internal class DirectoryElement : ConfigurationElement
      {
          [ConfigurationProperty("id", IsKey = true, IsRequired = true)]
          public int Id
          {
              get { return Convert.ToInt32(this["id"]); }
              set { this["id"] = value; }
          }
  
          [ConfigurationProperty("Path", IsKey = false, IsRequired = true)]
          public string Path
          {
              get { return Convert.ToString(this["Path"]); }
              set { this["Path"] = value; }
          }
  
          [ConfigurationProperty("Working", IsKey = false, IsRequired = true)]
          public string Working
          {
              get { return Convert.ToString(this["Working"]); }
              set { this["Working"] = value; }
          }
  
          [ConfigurationProperty("Country", IsKey = false, IsRequired = true)]
          public string Country
          {
              get { return Convert.ToString(this["Country"]); }
              set { this["Country"] = value; }
          }
      }
  }
  </code></pre>
  
  <p>And the code to use it </p>
  
  <pre><code>class SettingsContainer
  {
      private const string PARENT_SECTION = "MainSection";
  
      ...
      private DirectoriesSettings _directoriesSettings;
      public DirectoriesSettings Directories { get { return _directoriesSettings; } }
      ...
  
  
  
      public SettingsContainer()
      {
          ...
          _directoriesSettings = (DirectoriesSettings)ConfigurationManager.GetSection(string.Format("{0}/Directories", PARENT_SECTION));
          ...
      }
  
  }
  </code></pre>
  
  <p>The exception (Unrecognized element 'Directory') is thrown whenever I try to set the _directoriesSettings variable.</p>
  
  <p>I think I am doing it right, but apparently I am missing something.</p>
  
  <p>Any help will be greatly appreciated.</p>