I am sort of new to config files. I am aware that I can add key value pairs and that it's possible to access them and change them on the fly. I am attempting to implement the ChangeConfiguration method on https://blogs.msdn.microsoft.com/youssefm/2010/01/21/how-to-change-net-configuration-files-at-runtime-including-for-wcf/
However, I am getting:
"'ConfigurationManager' does not contain a definition for 'OpenExeConfiguration'"
...and I get the same for trying to use ConfigurationManager.RefreshSection()
I am aware that the instructions date back to 2010 so by the looks of it, these instructions seem to no longer be the correct procedure to do this...?
Context
- Web UI tests using Specflow, Selenium WebDriver, NUnit
- Class Library targeting .NET Framework 4.6.1
- Trying to add key value pairs at runtime in App.config
using System.Configuration; using System.Reflection;
namespace CoreSeleniumFramework.Managers
{
public class ConfigurationManager
{
static void ChangeConfiguration()
{
Configuration config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
appSettings.Settings.Clear();
appSettings.Settings.Add("name", "bar");
config.Save();
ConfigurationManager.RefreshSection("appSettings");
}
}
}