title: How can I have 2 different types of Collections in the root of a a custom configuration section?
body: <p>I created my first custom configuration section and all went well. Then I went to extend it and it went sideways. The problem I have and cant find a lot of example on is that inside my Section, I want to have 2 different types of collections. The elements in both collections are totally different but the same in each. I cant get the Configuration Section to return the correct Collection as I get errors. I could cheat and create 2 sections but that doesnt seem like the correct way to implement this.</p>
  
  <p>ok Some code</p>
  
  <pre><code>&lt;configSections&gt;
    &lt;section name="MyFileSection" type="My.ConfigManager.MyFileListConfiguration, MyConfigManager" /&gt;
  &lt;/configSections&gt;
  &lt;MyFileSection&gt;
    &lt;MyDirectoryRootCollection&gt;
      &lt;add rootName="MyDataLocation"   rootLocation="\\MyServer\MyDirectory"/&gt;
      &lt;add rootName="YourDataLocation" rootLocation="\\YourServer\YourDirectory"/&gt;
    &lt;/MyDirectoryRootCollection&gt;
    &lt;MyFileListCollection&gt;
      &lt;add keyName="MyFile1"   copyType="File" sourceFileName="TestFile1" /&gt;
      &lt;add keyName="MyFile2"   copyType="FTP"  sourceFileName="TestFile2" /&gt;
      &lt;add keyName="MyFile3"   copyType="File" sourceFileName="TestFile3" /&gt;
    &lt;/MyFileListCollection&gt;
  &lt;/MyFileSection&gt;
  </code></pre>
  
  <p>So inside MyFileSection, I have 2 collections... MyDirectoryRootCollection and MyFileListCollection. I thought the one Config class would let me get the 2 of them like this.</p>
  
  <pre><code>namespace My.ConfigManager
  {
      public class MyFileListConfiguration : ConfigurationSection
      {
          private static string sMyFileListCollectionConst      = "MyFileListCollection";
          private static string sMyDirectoryRootCollectionConst = "MyDirectoryRootCollection";
  
  
          [ConfigurationProperty("MyFileListCollection", IsDefaultCollection = false)]
          [ConfigurationCollection(typeof(MyFileListConfigEleCollection), AddItemName = "MyFileListCollection")]
          public MyFileListConfigEleCollection MyFileListCollection
          {
              get { return ((MyFileListConfigEleCollection)(base["MyFileListCollection"])); }
          }
  
          [ConfigurationProperty("MyDirectoryRootCollection", IsDefaultCollection = false)]
          [ConfigurationCollection(typeof(MyDirectoryRootConfigEleCollection), AddItemName = "MyFileListCollection")]
          public MyFileListConfiguration MyDirectoryRoot
          {
              get { return ((MyFileListConfiguration)(base["MyDirectoryRootCollection"])); }
          }
  
      }
  </code></pre>
  
  <p>I try and get the config section with this call</p>
  
  <pre><code>MyFileListConfiguration fileListSection = (MyFileListConfiguration)ConfigurationManager.GetSection("MyFileSection");
  </code></pre>
  
  <p>but I get this Error - </p>
  
  <blockquote>
    <p>System.Configuration.ConfigurationErrorsException was unhandled<br>
    Message="The Configuration property 'MyDirectoryRootCollection' may
    not be derived from ConfigurationSection."</p>
  </blockquote>
  
  <p>Has anyone any ideas what I am doing wrong and is it possible to have 2 totally different collections inside a section?</p>