RuntimeSection updates the configuration file at run time with this code:
private void ModifyRuntimeAppConfig() { XmlDocument modifiedRuntimeSection = GetResource("Framework35Rebinding"); if(modifiedRuntimeSection != null) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSection assemblyBindingSection = config.Sections["runtime"]; assemblyBindingSection.SectionInformation.SetRawXml(modifiedRuntimeSection.InnerXml); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("runtime"); } }
with Framework35Rebinding containing:
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.CompactFramework.Build.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="9.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime>
and app.config containing (before program execution):
<?xml version="1.0"?> <configuration> <startup> <supportedRuntime version="v2.0.50727"/> </startup> <runtime> </runtime> </configuration>
However, this does not work for what I want to do, because assemblyBinding is only read when the application starts, whereas RefreshSection("runtime")
Julien Hoarau
source share