title: How do I get the values from a ConfigSection defined as NameValueSectionHandler when using ConfigurationManager.OpenMappedExeConfiguration
body: <p>Getting the values from a config file that uses a section defined by System.Configuration.NameValueSectionHandler is easy when you're using the current config file for the application.</p>
  
  <p>Example Config file.</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="MyParams" type="System.Configuration.NameValueSectionHandler" /&gt;
    &lt;/configSections&gt;
  
    &lt;MyParams&gt;
      &lt;add key="FirstParam" value="One"/&gt;
      &lt;add key="SecondParam" value="Two"/&gt;
    &lt;/MyParams&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Example Code that easily reads it.</p>
  
  <pre><code>NameValueCollection myParamsCollection =
     ConfigurationManager.GetSection("MyParams") as NameValueCollection;
  </code></pre>
  
  <p>This is the code that doesn't work.</p>
  
  <pre><code>NameValueCollection collection =
    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    .GetSection("MyParams") as NameValueCollection;
  </code></pre>
  
  <p>That fails with the following error on compile.</p>
  
  <p>Cannot convert type 'System.Configuration.ConfigurationSection' to 'System.Collections.Specialized.NameValueCollection' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion.</p>
  
  <p>ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) returns a System.Configuration.Configuration, and Configuration.GetSection returns ConfigurationSection.</p>
  
  <p>ConfigurationManager.GetSection returns object.</p>
  
  <p>So, how do I get back my NameValueCollection when I have to use OpenExeConfiguration?</p>