Missing ConfigurationManager in WinForms

For anyone who switches back and forth between developing ASP.NET WebForms and WinForms, this tip may come in handy.

If you are developing in a C# WinForms project, you will find that attempting to use a ConfigurationManager to get at your app.config settings will result in the following error:

The name 'ConfigurationManager' does not exist in the current context

Since this is included by default in ASP.NET projects, this may come as a surprise. Just simply right-click on the References node in your project and look on the .NET tab. Scroll down and you should find System.Configuration. Add this to your project and you should be up and running.

Adding a Reference to System.Configuration

Provided you have already added System.Configuration to the using section at the top of your code, you should now be able to use config settings (such as connection strings) with code such as the following:

con.ConnectionString = ConfigurationManager.ConnectionStrings[sConnection].ConnectionString;

5 Responses

  1. thanks bro: it was a life saver. spent couple of hours trying to find configuration manager

  2. Perfect… worked like a gem!

  3. Hi Thanks for your suggestion it saved me lot of time

  4. Hey Now Scott,

    Nice Post,

    Thx 4 the info,

    Catto

  5. Hi its very helpful & saved my lot of time
    cheers

Leave a Reply