title: How to retrieve a custom section from an app.config in .NET?
body: <p>I have a .NET Framework 4.7.2 library project, inside there's an App.config file like this:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;section name=&quot;NewDocumentMetadata&quot; type=&quot;System.Configuration.NameValueSectionHandler&quot; /&gt;
      &lt;/configSections&gt;
      &lt;NewDocumentMetadata&gt;
          &lt;add key=&quot;Type&quot; value=&quot;principal&quot;/&gt;
          &lt;add key=&quot;IsActive&quot; value=&quot;true&quot;/&gt;
      &lt;/NewDocumentMetadata&gt;
      &lt;appSettings&gt;
          &lt;add key=&quot;Entity&quot; value=&quot;9&quot;/&gt;
          &lt;add key=&quot;Flux&quot; value=&quot;pdf&quot;/&gt;
      &lt;/appSettings&gt;
      &lt;runtime&gt;
          &lt;assemblyBinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&gt;
              &lt;!-- [...] --&gt;
          &lt;/assemblyBinding&gt;
      &lt;/runtime&gt;
  &lt;/configuration&gt;
  </code></pre>
  <p>As you can see, I have some standard settings, but also a custom section. I have no problems with the settings, but when I retrieve the section, it works, but there I'm stuck, when I try to cast it to <code>NameValueCollection</code> or <code>AppSettingsSection</code> it gives me a <code>null</code> value, I'm stuck with a <code>ConfigurationOption</code> object I am not able to work with.</p>
  <pre><code>        var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
  
          flux = appConfig.AppSettings.Settings[&quot;Flux&quot;].Value; //Works
          entity = appConfig.AppSettings.Settings[&quot;Entity&quot;].Value; //Works
  
          var metadataSection = appConfig.GetSection(&quot;NewDocumentMetadata&quot;); //What do I do with this boy?
  </code></pre>
  <p>I need to retrieve the settings within the <code>NewDocumentMetadata</code> section, how to proceed?</p>