ConfigurationManager.OpenMachineConfiguration Method

Opens the machine configuration file on the current computer as a Configuration object.

Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)

public static Configuration OpenMachineConfiguration ()
public static Configuration OpenMachineConfiguration ()
public static function OpenMachineConfiguration () : Configuration
Not applicable.

Return Value

A Configuration object.

Exception typeCondition


A configuration file could not be loaded.

Machine configuration settings apply to the whole computer and all applications that reside on it, unless overridden for the local application. Machine configuration settings are read from the Machine.config file of the currently running version of the .NET Framework. The Machine.config file is located in the following subdirectory:



To obtain the Configuration object for a resource, your code must have read permissions on all the configuration files from which it inherits settings. To update a configuration file, your code must additionally have write permissions for both the configuration file and the directory in which it exists. It is not possible to access the Machine.config file for other versions of the .NET Framework that might be installed on the computer.

The following code example shows how to use the OpenMachineConfiguration method to obtain all sections that are contained in the configuration file.

// Show how to use OpenMachineConfiguration.
static void DisplayMachineConfigSections()
    // Get the machine.config file.
    Configuration machineConfig =
    ConfigurationSectionCollection sections = machineConfig.Sections;

    Console.WriteLine("Sections in machine.config:");

    // Loop to get the sections machine.config.
    foreach (ConfigurationSection section in sections)
        string name = section.SectionInformation.Name;
        Console.WriteLine("Name: {0}", name);

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions