I have the following problem:
We have an application that loads modules (add ons). These modules might need entries in the app.config (e.g. WCF configuration). Because the modules are loaded dynamically, I don't want to have these entries in the app.config file of my application.
What I would like to do is the following:
- Create a new app.config in memory that incorporates the config sections from the modules
- Tell my application to use that new app.config
Note: I do not want to overwrite the default app.config!
It should work transparently, so that for example ConfigurationManager.AppSettings
uses that new file.
During my evaluation of this problem, I came up with the same solution as is provided here: Reload app.config with nunit.
Unfortunately, it doesn't seem to do anything, because I still get the data from the normal app.config.
I used this code to test it:
Console.WriteLine(ConfigurationManager.AppSettings["SettingA"]);
Console.WriteLine(Settings.Default.Setting);
var combinedConfig = string.Format(CONFIG2, CONFIG);
var tempFileName = Path.GetTempFileName();
using (var writer = new StreamWriter(tempFileName))
{
writer.Write(combinedConfig);
}
using(AppConfig.Change(tempFileName))
{
Console.WriteLine(ConfigurationManager.AppSettings["SettingA"]);
Console.WriteLine(Settings.Default.Setting);
}
It prints the same values twices, although combinedConfig
contains other values than the normal app.config.
AppDomain
with the appropriate configuration file is not an option? – João AngeloReload app.config with nunit
could work, not sure, if used on application entry before any configuration is loaded. – João Angelo