Sunday, 28 December 2014

C# - How to fix error - 'ConfigurationManager' does not exist in the current context

Watch this example on YouTube

Error when executing the following code:
    string ConfigValue = ConfigurationManager.AppSettings["MyKey"];
            MessageBox.Show(ConfigValue);

App.config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <appSettings>
      <add key="MyKey" value="MyValue"/>
    </appSettings>
</configuration>

To fix it:
add new reference - system.configuration.dll
add new "using" - using System.Configuration

No comments:

Post a Comment