Created
August 22, 2017 11:15
-
-
Save daveaglick/3eb907949c5058656c7f1f4d0fcbca62 to your computer and use it in GitHub Desktop.
Change config file at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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