none
Problem with the configurationManager Class

    Question

  • i'm trying to use the configurationManager to access the config file in my application but the compiler yells at me with the following error although i've imported the System.Configuration namespace.

    >> ConfigurationManager does not exist in the current context

    this is the code

    string my_Con = ConfigurationManager.AppSettings.Get("connectionstring"); // here i added a key in my app.Config file with the name connection and a valid connection string as the value...

    also the intellisense does not seem to show me the configurationManager class but when i check in the .net framework v2.0 installed in my C:\windows\Framework\.netframework i can see the ConfigurationManager under the namespace System.Configuration which i imported in my code. so i just don't understand

    thanks you in advance

    Sunday, October 08, 2006 5:18 PM

Answers

  • Hi!

    The same happened to me... I changed my code accordingly, but the project wouldn't compile. It turns out that you need to add a reference to System.Configuration to the project, rather than simply adding it with a using statement. This can be done as:

    Add a reference to System.Configuration by clicking Project -> Add Reference... and searching through the .NET components for System.Configuration

    I hope this helps...

    See you,

    Ciro


    Thursday, October 12, 2006 4:12 PM

All replies

  • Hi!

    The same happened to me... I changed my code accordingly, but the project wouldn't compile. It turns out that you need to add a reference to System.Configuration to the project, rather than simply adding it with a using statement. This can be done as:

    Add a reference to System.Configuration by clicking Project -> Add Reference... and searching through the .NET components for System.Configuration

    I hope this helps...

    See you,

    Ciro


    Thursday, October 12, 2006 4:12 PM
  • thanks Ciro it worked fine  that's cool

    thanks

     

    bye

    Friday, October 13, 2006 3:02 AM
  • after you add a reference to the dll you should save and close your VS Express and restart it for it to take work. (don't know why??? but it won't work without a restart. )
    Sunday, March 18, 2007 5:13 AM
  • Thank you!
    Friday, June 15, 2007 3:23 PM
  • Hi CiroTheodoro,

    Thank you for your answer.

    Saturday, June 16, 2007 5:11 PM
  • Hi All

    Just a note to say this is also a problem with Visual Studio 2005 Professional Edition - not just the express version.

    Cheers

    Tyrone

    Monday, October 15, 2007 5:35 PM
  • I've also found it to be a problem with VS 2008 Team Suite edition....

     

    David J.

     

    Wednesday, February 06, 2008 9:45 PM
  • Thanks for this answer.  I was having a dickens of a time with this.  Hope I can remember it next time...

    Thursday, February 07, 2008 2:24 AM
  • I too face the same problem thanks for u.
    Tuesday, March 18, 2008 7:54 AM
  •  

    Thanks for your help.. that did really work for me..
    Wednesday, August 13, 2008 5:42 AM
  • Here's a new twist on this problem:  if you have more than one project in a solution, you have to add the reference to System.Configuration to BOTH projects before it will work in either!!  Yikes!!
    • Proposed as answer by Lankymart Tuesday, March 19, 2013 4:03 PM
    Tuesday, October 28, 2008 2:43 PM
  •  

    This is also happen in my code. it is really nice. Thankyou for your support.
    Monday, December 08, 2008 11:47 AM
  • Hi All,
    Thanks for your valuable suggations,

    Here I would Like to make the things in a process...



    1. Right click on References >> Add new Reference >> Under .NET Tab find Sysstem.COnfiguration.
    2. In the c# Code under using  use  "  using System.Configuration;  " .
    3. Now you are ready to use  " ConfigurationManager.AppSettings " .

    Thanks,
    Sunil

    Sunilky
    Tuesday, December 16, 2008 5:08 AM
  • Hi Thanks,

    This is a great article ! It works for me  Thanks

    I have added the reference but then also it was not working because I had 3 projects in my solution now when I read your comment regarding the multiple project we have to add in all the project then I able to run the application.

    Again thanks for your suggestion .
    Friday, September 25, 2009 5:11 AM
  • Hi!

    I check this problem and find an issue that the System.Configuration is in version 2.0 And not in 3.5 when i see it in add reference dialog box. Thats why we have to add this separately.


    Thanks
    Amrish Verma
    Sr. Developer
    • Edited by Amrish Verma Thursday, December 24, 2009 6:17 AM Spelling Mistake
    Thursday, December 24, 2009 6:17 AM
  • thanks!!
    Sunday, January 17, 2010 6:03 PM
  • Hi All,
    Thanks for your valuable suggations,

    Here I would Like to make the things in a process...



    1. Right click on References >> Add new Reference >> Under .NET Tab find Sysstem.COnfiguration.
    2. In the c# Code under using  use  "  using System.Configuration;  " .
    3. Now you are ready to use  " ConfigurationManager.AppSettings " .

    Thanks,
    Sunil

    Sunilky

    Try it and see if it works for me, Here is also the same case.
    Tuesday, October 19, 2010 6:40 AM
  • Hi ,

    Use 

    string my_Con = ConfigurationSettings.AppSettings["connectionstring"],ToString();

    Instead of

    string my_Con = ConfigurationManager.AppSettings.Get("connectionstring");

    you will get what u wnat .

    • Proposed as answer by foxygirl-pc Tuesday, December 14, 2010 7:40 PM
    Friday, November 19, 2010 12:55 PM
  • yes i do get it. Thank You
    • Proposed as answer by Azar-S Tuesday, July 12, 2011 8:09 AM
    • Unproposed as answer by Azar-S Tuesday, July 12, 2011 8:09 AM
    Tuesday, December 14, 2010 7:41 PM
  • thanks Ciro it worked fine...

     

    Thanks alot...


    Tuesday, July 12, 2011 8:06 AM
  • Thanks a lot, same problem was there with me.. couldn't solve, even though tried a lot.. but your suggestion worked.. So thank you so much..

    But couldn't understand, how it makes difference adding reference system.configuration ?  Because we have already used using statement in code file..!!

    Wednesday, November 28, 2012 8:21 AM