title: How to store a collection of custom objects to an user.config file?
body: <p>I would like to store a collection of custom objects in a user.config file and would like to add and remove items from the collection programmatically and then save the modified list back to the configuration file.</p>
  
  <p>My items are of the following simple form:</p>
  
  <pre><code>class UserInfo
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Email { get; set; }        
  }
  </code></pre>
  
  <p>In my app.config I already created a custom section:</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="userInfo" type="UserInfoConfigurationHandler, MyProgram"/&gt;
  
    &lt;/configSections&gt;
    &lt;userInfo&gt;
      &lt;User firstName="John" lastName="Doe" email="john@example.com" /&gt;
      &lt;User firstName="Jane" lastName="Doe" email="jane@example.com" /&gt;
    &lt;/userInfo&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I am also able to read in the settings by implementing <code>IConfigurationSectionHandler</code>:</p>
  
  <pre><code>class UserInfoConfigurationHandler : IConfigurationSectionHandler
  {
      public UserInfoConfigurationHandler() { }
  
      public object Create(object parent, object configContext, System.Xml.XmlNode section)
      {
          List&lt;UserInfo&gt; items = new List&lt;UserInfo&gt;();
          System.Xml.XmlNodeList processesNodes = section.SelectNodes("User");
  
          foreach (XmlNode processNode in processesNodes)
          {
              UserInfo item = new UserInfo();
              item.FirstName = processNode.Attributes["firstName"].InnerText;
              item.LastName = processNode.Attributes["lastName"].InnerText;
              item.Email = processNode.Attributes["email"].InnerText;
              items.Add(item);
          }
          return items;
      }
  }
  </code></pre>
  
  <p>I did all this following this <a href="http://www.dotneat.net/2007/10/16/StoringACollectionOnYourAppconfigUsingSectionHandlers.aspx" rel="noreferrer">article</a>. However, using this approach I'm only able to <strong>read</strong> the settings from app.config into a <code>List&lt;UserInfo&gt;</code> collection, but I would also need to <strong>write</strong> a modified list back. </p>
  
  <p>I was searching the documentation without success and now I'm kind of stuck. What am I missing?</p>