Last active
May 31, 2016 20:48
-
-
Save pvandenheede/80444f808e55ede60b6fe629eb94a58a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the machine.config file. | |
Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration(); | |
// Get the machine.config file path. | |
ConfigurationFileMap configFile = new ConfigurationFileMap(machineConfig.FilePath); | |
// Map the application configuration file to the machine configuration file. | |
Configuration config = ConfigurationManager.OpenMappedMachineConfiguration(configFile); | |
ConfigurationSectionGroup svcModel = config.SectionGroups.Get("system.serviceModel"); | |
ExtensionsSection extensions = (ExtensionsSection) svcModel.Sections.Get("extensions"); | |
ExtensionElement e = new ExtensionElement("MyName", "MyType, MyNamespace.MyType, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4275f802b89cdd22"); | |
extensions.BehaviorExtensions.Add(e); | |
extensions.SectionInformation.ForceSave = true; | |
config.Save(ConfigurationSaveMode.Full); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment