Note that there are some explanatory texts on larger screens.

plurals
  1. POChange default app.config at runtime
    primarykey
    data
    text
    <p>I have the following problem:<br> 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.<br> What I would like to do is the following:</p> <ul> <li>Create a new app.config in memory that incorporates the config sections from the modules</li> <li>Tell my application to use that new app.config</li> </ul> <p>Note: I do not want to overwrite the default app.config!</p> <p>It should work transparently, so that for example <code>ConfigurationManager.AppSettings</code> uses that new file.</p> <p>During my evaluation of this problem, I came up with the same solution as is provided here: <a href="https://stackoverflow.com/questions/949696/reload-app-config-with-nunit">Reload app.config with nunit</a>.<br> Unfortunately, it doesn't seem to do anything, because I still get the data from the normal app.config.</p> <p>I used this code to test it:</p> <pre><code>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); } </code></pre> <p>It prints the same values twices, although <code>combinedConfig</code> contains other values than the normal app.config.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload