Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change config file at runtime
// Set app.config - http://stackoverflow.com/a/6151688/807064
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\new.config");
typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, 0);
typeof(ConfigurationManager)
.GetField("s_configSystem", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, null);
typeof(ConfigurationManager).Assembly.GetTypes()
.Where(x => x.FullName == "System.Configuration.ClientConfigPaths")
.First().GetField("s_current", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.