70

I have included the following statement in my Visual C# Console Application (Visual Studio 2005 .NET 2.0 Framework)

using System.Configuration;

and I am using the following statement in my application:

ConfigurationManager.AppSettings["SomeStringOverHere"];

I try to build the application and I get the error: The name 'ConfigurationManager' does not exist in the current context.

Any help please?

Brandon
  • 68,708
  • 30
  • 194
  • 223
zack
  • 7,115
  • 14
  • 53
  • 63

4 Answers4

112

You need to reference System.Configuration.dll in your project as well as the "using" statement.

Namespaces are (sometimes) "split" across assemblies. That means that types in a single namespace are actually in different assemblies.

To determine which assembly a BCL or FCL type is in, look it up on MSDN. If you look at the help for ConfigurationManager, you'll see that it specifies that it's in the System.Configuration assembly by looking near the top at "Assembly". This is the assembly you need to reference from your project

Philip Rieck
  • 32,368
  • 11
  • 87
  • 99
  • 7
    I have the same problem, I am using the "Using using System.Configuration;" and the reference as well... still dows not work... do I have to reference to the using System.Configuration.bll as well? where I can find it... is not in the add reference. Thank you ! – Gerardo Jaramillo Jan 28 '11 at 15:13
  • 2
    I just wasted a few minutes on this issue before I remembered that there are two parts to the solution. Not only do you need the using directive, but you also need a reference to the System.Configuration assembly, itself. – David A. Gray Dec 16 '16 at 15:30
24

Philip was correct adding the reference helped me, but I actually went and tried to download the DLL because I did not know there was an easier way...

  1. right-click on 'add references' folder in the solution explorer
  2. select the '.NET' tab
  3. search for the .NET reference you would like to add (in this case System.Configuration)

This post was very helpful to me, thanks to all.

Taylor Brown
  • 1,689
  • 2
  • 17
  • 33
  • 2
    OP is already using `using System.Configuration;` OP needed to add reference to `System.Configuration.dll` in his/her project as advised by @PhilipRieck. – nam May 31 '16 at 20:36
4
  • at the solution explorer
  • select References
  • then click Add Reference from the right mouse button menu

enter image description here

  • in the top right corner write "Configuration:
  • check the System.Configuration, which would show up
  • press OK

enter image description here

Vityata
  • 42,633
  • 8
  • 55
  • 100
1

I faced the same problem too.

I have 2 projects 1 main and 1 DLL. I have App.config file in the same Place But Connection string was defined in DLL but not in main project which is executable one as main. after adding / moving the connection string to main project APP.CONFIG file, the issue resolved.

Hope this helps

Hasan Elsherbiny
  • 598
  • 2
  • 14
  • 31
ಅನಿಲ್
  • 606
  • 5
  • 7
  • 1
    Move you parameter to main Project "Config" file Add Reference "System.Configuration" Provide "Using System.configuration" statement on top – ಅನಿಲ್ Jul 28 '16 at 15:35