Unable to use C# ConfigurationManager
Asked Answered
P

4

16

I have the following code:

using System.Configuration;

namespace test
{
  public partial class MyService : ServiceBase
  {
    public  static ReadConnectionStrings()
    {                        
      ConnectionStringSettingsCollection connections =
          ConfigurationManager.ConnectionStrings;

However, it doesn’t recognise ConfigurationManager. I took this code directly from here

So I’m clearly missing something, but can’t identify what.

Plosion answered 6/10, 2010 at 14:41 Comment(0)
S
46

Do you have a reference to System.Configuration? It's not added to .NET projects by default.

Stillwell answered 6/10, 2010 at 14:45 Comment(1)
What if this is shared project?Sudan
L
18

I was having the same issue.

It took me a little while to figure out that adding the reference is not adding the using. I had to right-click the project and select Add Reference, then pick System.Configuration in the .NET tab.

Worked like a charm!

Lewandowski answered 6/10, 2010 at 20:22 Comment(0)
T
1

Ensure that the actual project you're working in has a reference to System.Configuration. I was working in a data access project, not the presentation layer's project. So I was getting a bit confused because I had thought I had a reference, but in reality the data project was missing the reference.

Telpher answered 25/2, 2015 at 14:28 Comment(0)
M
0

I had to download the assembly refernce then add to project not sure if others had this problem

Minacious answered 11/6, 2012 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.