If I have in myprogram.exe.config file:
<configuration>
<configSections>
<section name="fooSection" type="MyNamespace.MySection, My.Assembly"/>
</configSections>
<appSettings>
<add key="foo" value="bar"/>
</appSettings>
<fooSection>
<bar>
<add baz="foo bar baz"/>
</bar>
</fooSection>
</configuration>
and I have in overrides.config file:
<configuration>
<configSections>
<section name="fooSection" type="MyNamespace.MySection, My.Assembly"/>
</configSections>
<appSettings>
<add key="foo" value="BAZ"/>
</appSettings>
<fooSection>
<bar>
<add baz2="foo foo"/>
</bar>
</fooSection>
</configuration>
Is there any way to have this read into the core (or loaded) configuration, like you would get with the machine->app config file precendence? (or even machine.config -> machine root web.config -> local app web.config)
In this example, I would like config.AppSettings["foo"] to be "BAZ" and fooSection to contain two items: "foo bar baz" and "foo foo".
I cannot find a way, and am guessing it may not be supported. I've tried many permutations.
MySection section = ConfigurationManager.GetSection("foo") as MySection;
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.LocalUserConfigFilename = // have tried this;
fileMap.ExeConfigFilename = // have tried this
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
ConfigurationManager.RefreshSection("foo");
foo = ConfigurationManager.GetSection("foo") as MySection;
// will only have one item
foo = config.GetSection("foo") as MySection;
// will only have one item