title: What's wrong with my App.config?
body: <p>I've been tasked to extend our app's App.config by creating a <code>&lt;configSection&gt;</code> in which we'd define a relatively complex object in Xml. The config looks like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="MinWaitTime" value="150" /&gt;
      &lt;add key="MaxWaitTime" value="900" /&gt;
    &lt;/appSettings&gt;
    &lt;configSections&gt;
      &lt;section name="clientconfig" type="KeepWarm.ClientConfig" /&gt;
    &lt;/configSections&gt;
    &lt;clientconfig username="test user" password="test password"&gt;
      &lt;urls&gt;
        &lt;add url="test1" /&gt;
        &lt;add url="test2" /&gt;
        &lt;add url="test3" /&gt;
      &lt;/urls&gt;
    &lt;/clientconfig&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Eventually, I'll have to be able to define multiple <code>&lt;clientconfig&gt;</code>, but I'm already struggling getting only one to work.</p>
  
  <pre><code>namespace KeepWarm
  {
      public class ClientConfig : ConfigurationSection
      {
          [ConfigurationProperty("username", IsRequired = true)]
          public string UserName
          {
              get { return (string)base["username"]; }
              set { base["username"] = value; }
          }
  
          [ConfigurationProperty("password", IsRequired = true)]
          public string Password
          {
              get { return (string)base["password"]; }
              set { base["password"] = value; }
          }
  
          [ConfigurationProperty("urls", IsRequired = true)]
          public UrlCollection Urls
          {
              get { return (UrlCollection)base["urls"]; }
              set { base["urls"] = value; }
          }
      }
  
      [ConfigurationCollection(typeof(UrlElement))]
      public class UrlCollection : ConfigurationElementCollection
      {
          protected override ConfigurationElement CreateNewElement()
          {
              return new UrlElement();
          }
  
          protected override object GetElementKey(ConfigurationElement element)
          {
              return ((UrlElement)element).Url;
          }
      }
  
      public class UrlElement : ConfigurationElement
      {
          [ConfigurationProperty("url", IsKey = true, IsRequired = true)]
          public string Url
          {
              get { return (string)this["url"]; }
              set { base["url"] = value; }
          }
      }
  }
  </code></pre>
  
  <p>Yet whenever I try to access my settings, like this:</p>
  
  <pre><code>var minWaitTime = int.Parse(ConfigurationManager.AppSettings["MinWaitTime"]);
  </code></pre>
  
  <p>I get a <code>System.Configuration.ConfigurationErrorsException</code>.</p>
  
  <p>I've been looking at various examples online, but nothing seems to help in my case. What am I doing wrong?</p>