title: Custom Config section in App.config C#
body: <p><br/>
  I'm a quite beginner with config sections in c#<br/>
  I want to create a custom section in config file. What I've tried after googling is as the follows<br/>
  Config file:
  <br/></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;sectionGroup name="MyCustomSections"&gt;
        &lt;section name="CustomSection" type="CustomSectionTest.CustomSection,CustomSection"/&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
  
    &lt;MyCustomSections&gt;
      &lt;CustomSection key="Default"/&gt;
    &lt;/MyCustomSections&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><br/>
  CustomSection.cs
  <br/></p>
  
  <pre><code>    namespace CustomSectionTest
  {
      public class CustomSection : ConfigurationSection
      {
          [ConfigurationProperty("key", DefaultValue="Default", IsRequired = true)]
          [StringValidator(InvalidCharacters = "~!@#$%^&amp;*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
          public String Key
          {
              get { return this["key"].ToString(); }
              set { this["key"] = value; }
          }
      }
  }
  </code></pre>
  
  <p><br/>
  When I use this code to retrieve Section I get an error saying configuration error.<br/></p>
  
  <pre><code>var cf = (CustomSection)System.Configuration.ConfigurationManager.GetSection("CustomSection");
  </code></pre>
  
  <p><br/>
  What am I missing?<br/>
  Thanks.<br/><br/>
  <strong>Edit</strong>
  <br/>
  What I need ultimately is</p>
  
  <pre><code>    &lt;CustomConfigSettings&gt;
      &lt;Setting id="1"&gt;
          &lt;add key="Name" value="N"/&gt;
          &lt;add key="Type" value="D"/&gt;
      &lt;/Setting&gt;
      &lt;Setting id="2"&gt;
          &lt;add key="Name" value="O"/&gt;
          &lt;add key="Type" value="E"/&gt;
      &lt;/Setting&gt;
      &lt;Setting id="3"&gt;
          &lt;add key="Name" value="P"/&gt;
          &lt;add key="Type" value="F"/&gt;
      &lt;/Setting&gt;
  &lt;/CustomConfigSettings&gt;
  </code></pre>