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;


11 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,


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

  6. hey, your post truly helps, now i happen the same problems, and i donot know on how to solve the issue. luckily i research google and discovered your post, it helps me get rid of my trouble. thanks once againone thing, may i paste your entry on my blog? i will add the source.regards!

  7. Hi Scott,

    I have been looking for this reply for months – thanks a lot, man!!

  8. Thanks a lot, it’s an aswer on my bewilderment! Thought I dont understand why it is necessary to do so while its done in using…

  9. Thanks Very much

  10. Thanks for the post, by the way, is it the correct that by putting your connection string setting in app.config? or is there any better way?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: