Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid "The name 'ConfigurationManager' does not exist in the current context" error?

I am using VS2008. I have a project connect with a database and the connection string is read from App.config via ConfigurationManager. We are using L2E.

Now I added a helper project, AndeDataViewer, to have a simple UI to display data from the database for testing/verification purpose.

I don't want to create another set of Entity Data Model in the helper project. I just added all related files as a link in the new helper project.

When I compile, I got the following error:

Error   15  The name 'ConfigurationManager' does not exist in the current context   C:\workspace\SystemSoftware\SystemSoftware\src\systeminfo\RuntimeInfo.cs    24  40  AndeDataViewer

I think I may need to add another project setting/config related file's link to the helper project from the main project? There is no App.config file in the new helper project. But it looks I cannot add that file's link to the helper project. Any ideas?

like image 789
5YrsLaterDBA Avatar asked Apr 30 '10 14:04

5YrsLaterDBA


People also ask

How do I override ConfigurationManager appSettings?

It appears there is a way to do this in . NET 3.5 by setting the allowOverride attribute in the appSettings definition section of machine. config. This allows you to override the entire section in your own app.

What is ConfigurationManager C#?

ConfigurationManager is the class which helps to read data from configurations. Provides access to configuration files for client applications. Namespace: System.Configuration. To use the ConfigurationManager class, your project must reference the System.

What is ConfigurationManager configuration?

The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class, which is deprecated. For web applications, use the WebConfigurationManager class.

What is the use of ConfigurationManager appSettings?

GetSection(String) Method (System. Configuration) Retrieves a specified configuration section for the current application's default configuration.


2 Answers

In your project, right-click, Add Reference... In the .NET tab, find the "System.Configuration" component name and click OK.

"using System.Configuration" tells the compiler/IntelliSense to search in that namespace for any classes you use. Otherwise you would have to use the full name (System.Configuration.ConfigurationManager) every time. But if you don't add the reference, that namespace/class will not be found anywhere.

Note that a DLL can have any namespace, so the file System.Configuration.dll could in theory have the namespace "Some.Random.Name". For clarity/consistency they're usually the same, but there are exceptions.

like image 110
Nelson Rothermel Avatar answered Sep 22 '22 10:09

Nelson Rothermel


In case you get are trying to access the cloud configuration file in your Azure Cloud service and get the error

CloudConfigurationManager does not exist in the current context

on CloudConfigurationManager class, then all you need to do is add the nuget package Microsoft.WindowsAzure.ConfigurationManager to your project.

And then, make sure you include the using statement "using Microsoft.Azure" in the class where you’re trying to access the cloud configuration file.

Hope this helps!!

like image 24
goldy Avatar answered Sep 23 '22 10:09

goldy