Is System.Configuration.ConfigurationManager unavailable?

In the VS2005 C # project, I added a link to System.configuration. In Object Explorer, I see System.Configuration.ConfigurationManager. In Intellisense System.Configuration, only the old ConfigurationSettings, not the ConfigurationManager.

My code is System.Configuration.ConfigurationManager.AppSettings ["MySetting"]

stands out as a syntax error and does not compile.

In another project, exactly the same setup works just fine ... any clues as to what is going on?

+52
configurationmanager
May 12 '09 at 8:42
source share
8 answers

urgh - PICNIC error. Added ref to the wrong project in the solution ...

+10
May 12 '09 at 9:00 a.m.
source share

Although using System.Configuration; the command is automatically generated in the use section, for some reason the actual link is not installed.

Go to the add link, the .Net tab and select "System.Configuration".

ConfigurationManager will now be enabled.

If you go to a project where exactly the same setup works very well and look at the links, you will see a link to System.Configuration.

+119
May 13 '09 at 20:31
source share

To answer the question (and not that it has not answered 5+ times already), you need to add System.Configuration as a link to your project.

However, I would like to highlight that in many cases I added System.Configuration.dll to my project links, but for some special reason sometimes the ConfigurationManager will still not appear in intellisense even after adding a link to System.Configuration. Even if I delete the link and add it again.

A very simple solution to this problem:

  • Add the link to System.Configuration.dll to your project
  • Save your files
  • Save the decision.
  • Close the instance of Visual Studio that is making your time difficult.
  • Open your decision

This simple exercise will cause Visual Studio to behave again and stop telling you that you have not added a link to System.Configuration. This exercise usually helps me with all the inexplicable behaviors of Visual Studio.

This happened to me both in VS2008 and VS2010 several times, and it works every time.

+16
Aug 16 '12 at 22:21
source share

For those who switch back and forth between ASP.NET WebForms and WinForms, this review may come in handy.

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

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

Since this is enabled by default in ASP.NET projects, this may come as a surprise. Just right-click on the β€œLinks” node in your project and look at the β€œ.NET” tab. Scroll down and you should find System.Configuration . Add this to your project and you should be operational.

Adding a reference to System.Configuration

If you have already added System.Configuration to the use section at the top of the code, now you can use the configuration settings (for example, connection strings) with the code, for example:

 con.ConnectionString = ConfigurationManager.ConnectionStrings[sConnection].ConnectionString; 
+9
Jul 02 '09 at 11:35
source share

I think you need to indirectly reference the System.Configuration assembly.

+3
May 12 '09 at 9:46 a.m.
source share

In the MSDN documentation -

To use the ConfigurationManager class, your project must reference the System.Configuration assembly. By default, some project templates, like a console application, do not link to this assembly, so you must manually link to it.

https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

+3
Jun 17 '16 at 18:54
source share

This is just an assumption, but maybe you should check to see if your project uses at least the .NET framework 2.0. The ConfigurationManager class is available with .NET 2.0, as described here: msdn link

0
May 12, '09 at 8:54
source share
  1. Go to NuGet Package Management
  2. View System.Configuration
  3. Install the System.Configuration.ConfigurationManager package. View
0
Jun 27 '19 at 6:31
source share



All Articles