I am having an issue with an asp.net app where the web.config is updated and reloaded dynamically.
The following code is used to save the appsettings
section in web.config
:
public static void SetWebConfigValue(string keyValue, string value, bool isDefault)
{
if (!string.IsNullOrEmpty(keyValue))
{
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettings = config.AppSettings;
KeyValueConfigurationCollection settings = appSettings.Settings;
if (KeyExists(settings.AllKeys, keyValue))
{
settings.Remove(keyValue);
}
if (!isDefault) settings.Add(keyValue, value);
config.Save(ConfigurationSaveMode.Modified, true);
}
}
This code works just fine when I deploy the web app using on a machine with the .net 4.0 runtime. However, on a machine with the .net 4.7 runtime installed, an extra (empty) <System.Windows.Forms.ApplicationConfigurationSection />
is added to web.config. Since this setting cannot be empty, this crashes the web app when the web.config
is reloaded.
Edit: Question: why does the latest .net 4.7 adds an invalid configsection to my web.config?
Edit 2: the following issue has been created: https://github.com/Microsoft/dotnet/issues/435