ConfigurationBuilder Class


Represents the base class to be extended by custom configuration builder implementations.

public ref class ConfigurationBuilder abstract : System::Configuration::Provider::ProviderBase
public abstract class ConfigurationBuilder : System.Configuration.Provider.ProviderBase
type ConfigurationBuilder = class
    inherit ProviderBase
Public MustInherit Class ConfigurationBuilder
Inherits ProviderBase


The following example shows how to implement a simple ConfigurationBuilder to read Environment variables:

using System;
using System.Configuration;
using System.Xml;

namespace Samples.AspNet.Config

   public class SampleConfigurationBuilder : ConfigurationBuilder

        public override XmlNode ProcessRawXml(XmlNode rawXml) 

            string rawXmlString = rawXml.OuterXml;

            if (String.IsNullOrEmpty(rawXmlString)) {
                return rawXml;

            rawXmlString = Environment.ExpandEnvironmentVariables(rawXmlString);

            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            return doc.DocumentElement;

        public override ConfigurationSection ProcessConfigurationSection(ConfigurationSection configSection) 
            => configSection;
Imports System.Configuration
Imports System.Xml

Public Class SampleConfigurationBuilder : Inherits ConfigurationBuilder

    Public Overrides Function ProcessRawXml(rawXml As XmlNode)  As XmlNode

        Dim rawXmlString As String = rawXml.OuterXml

        If String.IsNullOrEmpty(rawXmlString) Then
            Return rawXml
        End If

        rawXmlString = Environment.ExpandEnvironmentVariables(rawXmlString)

        Dim doc As New XmlDocument()
        doc.PreserveWhitespace = True
        Return doc.DocumentElement
    End Function

    Public Overrides Function ProcessConfigurationSection(configSection As ConfigurationSection)  As ConfigurationSection
       Return configSection
    End Function

End Class

The following example is an excerpt of the configuration file as it applies to the previous example. This applies environment variables to the appSettings configuration and makes those values available under ConfigurationManager.AppSettings.

<!-- To declare and use Configuration Builders in your configuration chain, update your app.config or web.config file as follows:  -->

  <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false"/>

    <add name="SampleConfigurationBuilder" type="CustomConfigBuilders.MyConfigBuilder, CustomConfigBuilders" />

<!-- To apply Configuration Builders to a configuration section, use the 'configBuilders' tag as follows:  -->
<appSettings configBuilders="SampleConfigurationBuilder">
  <add key="COMPUTERNAME" value="Will Be Replaced by EnvironmentVariable" />


Derive from this class to read configuration from an external source that you would like to consume in your .NET Framework application using the standard ConfigurationManager API. ConfigurationBuilders are available on to read from environment variables, Azure key vault, and a number of other sources.

Several implementations of ConfigurationBuilders are available from



Initializes a new instance of the ConfigurationBuilder class.



Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(Inherited from ProviderBase)

Gets the friendly name used to refer to the provider during configuration.

(Inherited from ProviderBase)



Determines whether the specified object is equal to the current object.

(Inherited from Object)

Serves as the default hash function.

(Inherited from Object)

Gets the Type of the current instance.

(Inherited from Object)
Initialize(String, NameValueCollection)

Initializes the configuration builder.

(Inherited from ProviderBase)

Creates a shallow copy of the current Object.

(Inherited from Object)

Accepts a ConfigurationSection object from the configuration system and returns a modified or new ConfigurationSection object for further use.


Accepts an XmlNode representing the raw configuration section from a config file and returns a modified or new XmlNode for further use.


Returns a string that represents the current object.

(Inherited from Object)

Applies to