Resources » Errors and Solutions » Windows Errors

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


Last Updated:   Category: Windows Errors    
Author: Member Level: Gold    Points: 30


Are you trying to use the class ConfigurationManager in your .NET desktop application and getting the error "Error 4 The name 'ConfigurationManager' does not exist in the current context"? Read this post to find how to resolve this error and how to use ConfigurationManager class in place of old ConfigurationSettings class.



I have been using the old ConfigurationSettings in many of my old .NET applications to read configuration data from the app.config file. I knew this class was outdated and VS.NET kept reminding me about replacing it with the new ConfigurationManager class. Since the old code worked well, I did not feel the need to replace it with the new class. So, I left all my old code as it is.

Today I was developing a Google+ API library for .NET and had to read few configuration from the config file. I thought I would use the new ConfigurationManager class to read the data from the app.config file instead of sticking to the old class.

I typed the class ConfigurationManager and expected the intellisense to help me how to proceed. Surprisingly, intellisense complained it could not recognize and it suggested me to generate a new class with that name. I double checked and confirmed I am using the right class name. Everything looked alright and still Visual Studio could not recognize the class.

A quick look at MSDN showed me the System assembly where this class is defined. I looked at the project references and found this assembly is not referenced in the project references. Adding a reference to System.configuration.dll solved this problem.

Are you also getting the error Error 4 The name 'ConfigurationManager' does not exist in the current context?

Try the following steps:

  • Right click on "References" in your project

  • Choose 'Add references'

  • Choose the tab '.NET'

  • Scroll down and select 'System.Configuration'


  • Once you add a reference to System.Configuration, you should be able to use ConfigurationManager class, which is part of the System.Configuration namespace. So, remember to import the namespace as shown below:

    C# Example:

    using System.Configuration;

    VB.NET Example:

    imports System.Configuration

    Once you add a reference to the System.Configuration assemly and use the namespace as shown above, you should be able to use the ConfigurationManager without any error. Here is an example of how to use it to read configuration settings from app settings file.

    Example:

    string customerId = ConfigurationManager.AppSettings["CustomerId"];


    Read related articles: ConfigurationManager    ConfigurationSettings    

    Did you like this resource? Share it with your friends and show your love!

    Responses to "Error 4 The name 'ConfigurationManager' does not exist in the current context"
    Guest Author: Anurag     01 Aug 2012
    Why micosoft dont provide ConfigurationManager class in windows project. but it is available by default in asp.net


    Feedbacks      

    Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Jeevan Joshi
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India