title: How to read an object from app.config?
body: <p>This is not a new question, but I've been researching this for two days and all the answers I can find are outdated or unhelpful. What I want to do is put an object into App.config and then load it when the program starts.</p>
  
  <p>I've got a basic class called "Person" with three autoproperties: (string) FirstName, (string) LastName, and (int) Age. Here's my App.config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;startup&gt;&lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/&gt;&lt;/startup&gt;
    &lt;configSections&gt;
      &lt;sectionGroup name="People"&gt;
        &lt;section 
          name="Person" 
          type="Person.Person"
        /&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
    &lt;People&gt;
      &lt;Person&gt;
        &lt;Person type="Person.Person, Person"&gt;
          &lt;FirstName&gt;Jimmy&lt;/FirstName&gt;
          &lt;LastName&gt;Dean&lt;/LastName&gt;
          &lt;Age&gt;2&lt;/Age&gt;
        &lt;/Person&gt;
      &lt;/Person&gt;
    &lt;/People&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And here is my program:</p>
  
  <pre><code>using System;
  using System.Configuration;
  
  namespace AppConfigTest
  {
      class AppConfigTester
      {
          public static void Main(string[] args)
          {
              var guy = (Person.Person) ConfigurationManager.GetSection("People/Person");
              Console.WriteLine(guy.FirstName);
              Console.WriteLine(guy.LastName);
              Console.WriteLine(guy.Age);
          }
      }
  }
  </code></pre>
  
  <p>At the moment it crashes with a ConfigurationErrorsException. Any help would be very appreciated. It's boggling my mind that this is so difficult, when App.config is supposed to make doing this sort of thing easier.</p>