We have an old .NET 3.5 application deployed out to multiple remote systems. This application supports a plugin architecture that lets us download additional assemblies to the service whenever it starts up. I'm trying to modify the application's app.config to add .NET 4.0 as a supportedRuntime to allow us to use plugin assemblies with a higher version than 3.5. I'm checking registry keys and Environment.Version to see what's installed and what's currently supported before modifying the web.config as follows:
private static bool EnableNet4Support()
{
try
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var startupSection = config.GetSection("startup");
startupSection.SectionInformation.SetRawXml(@"
<startup><supportedRuntime version=""v4.0"" />
<supportedRuntime version=""v2.0.50727"" /></startup>");
config.Save(ConfigurationSaveMode.Full);
return true;
}
catch (Exception ex)
{
TraceHelper.WriteLine(ex.GetBaseException().ToString());
}
return false;
}
This method is working fine when I test locally, but when I push to one of our test environments it doesn't work as expected. The application can see .NET 4.8 is installed, so it makes the change to the web config. Once I verify the config is updated correctly, I manually restart the service, or even shut down and start up. When I do Environment.Version is still 2.0 even though the config suggests to use .NET 4.0 first.
These services are installed as a Windows Service, if that matters, and there wasn't a <startup> element in the config when I started. I assume that just means the executing assembly gets to decide what to use, right?
Any help is appreciated. Thanks!