I'd like to know a way to get all the sections names inside the tag configSections on my App.Config file.
So far what I've found is something like this:
var cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var localSections = cfg.Sections.Cast<ConfigurationSection>().Where(s => s.SectionInformation.IsDeclared);
But for some reason localSections always appears to be null. Here is how my app.config file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="frequency" value=""/>
</appSettings>
<configSections>
<section name="Name1" type="System.Configuration.NameValueSectionHandler" />
<section name="Name2" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<Name1>
<add key="active" value="on"/>
<add key="repeat" value="off"/>
</Name1>
<Name2>
<add key="active" value="on"/>
<add key="repeat" value="off"/>
</Name2>
</configuration>