Skip to content

Instantly share code, notes, and snippets.

@pvandenheede
Last active May 31, 2016 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvandenheede/80444f808e55ede60b6fe629eb94a58a to your computer and use it in GitHub Desktop.
Save pvandenheede/80444f808e55ede60b6fe629eb94a58a to your computer and use it in GitHub Desktop.
// 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