views:

288

answers:

2

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?

A: 

I think you're missing a reference to System.Configuration.dll or a using System.Configuration clause

Thomas Levesque
Where is the "System.Configuration.dll"? the using System.Configuration clause is there.
5YrsLaterDBA
+2  A: 

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.

Nelson
Thank you so much! It really works!
5YrsLaterDBA
Yup, this one stumped me once when I was starting to learn .NET. The references say where to look for code, while using is only to avoid typing the full namespace every time. It works the same with your own external (DLL) code.
Nelson
Oh, and if you ever want to delete that reference, expand the "References" folder in the project and right-click, remove it there.
Nelson
To help you understand this a bit more, you can also right click the references and then "View in Object Browser". Or go to the View menu, and choose Object Browser. The first level in the hierarchy are the DLLs, the second level are the namespaces in that DLL. It's simply a way of grouping code together.
Nelson
really appreciate your input.
5YrsLaterDBA