In a VS2005 C# project I have added a reference to System.configuration. In the object browser, I can see the System.Configuration.ConfigurationManager. In Intellisense Syst
It's just a guess, but maybe you should check if your project is using at least .NET framework 2.0. ConfigurationManager class is availvable since .NET 2.0 as dfescribed here: link on msdn
From the MSDN documentation -
To use the ConfigurationManager class, your project must reference the System.Configuration assembly. By default, some project templates, like Console Application, do not reference this assembly so you must manually reference it.
https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
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.
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;
I think you need to implicitly refer to System.Configuration assembly.
Although the using System.Configuration; command is automatically generated in the using section, for some reason the actual reference is not set.
Go into add reference, .Net tab, and choose System.Configuration.
ConfigurationManager will now be resolved.
If you go to the project where the exact same setup works just fine and look at the references, you will see a reference to System.Configuration.