ConfigurationManager.RefreshSection("AppSettings") doesn't work

I am trying to get a (ClickOnce deployed) application to read the non-default config file, depending on an environment variable set on the

_envName = System.Environment.GetEnvironmentVariable("ENV");
if (_envName == null)
    throw new Exception ("The ENV environemnt variable must be set");

string envFileName = "app." + _envName.ToLower() + ".config";

System.Configuration.Configuration config = 
config.AppSettings.File = envFileName;


This doesn't work! i.e. if the env varibale ENV is set to dvlp, the code runs, but values in the file app.dvlp.config are not accessible.

Can anyone see why this doesn't work? Or suggest a way I can have separate files, for each environment / machine and have them used accordingly.

This really ought to be much more simple.




Here is a blog article from the ClickOnce product lead at Microsoft with a way to handle app.config files for different build configurations. Hope it helps.

I'm pretty sure you can't access stuff outside of your sand boxed area with a ClickOnce install.

That said if I'm wrong I'd love to know the answer too :)

are you passing correct parameter I noticed you have capital AppSettings not appSettings

Need Your Help

C# WMI Eventwatcher code stopped working on Windows 7 with security exception

windows-7 wmi

This is code that worked fine on Windows XP for years. User is not local administrator.

symfony2 and twig for on sub-array

for-loop symfony twig

Alright, I've got an array that looks like.