how to update assemblyBinding section in config file at runtime?

后端 未结 3 1779
庸人自扰
庸人自扰 2020-12-10 14:47

I\'m trying to change assembly binding (from one version to another) dynamically.

I\'ve tried this code but it doesn\'t work:

      Configuration con         


        
3条回答
  •  天命终不由人
    2020-12-10 15:27

    RuntimeSection of the config file update at runtime using 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:

    
      
        
          
          
        
        
          
          
        
      
    
    

    and an app.config containing (before the execution of the program):

    
    
      
        
      
      
      
    
    

    Nevertheless it doesn't work for that I wanna do because assemblyBinding is only read at startup of the application whereas the RefreshSection("runtime")

提交回复
热议问题