18

So, I have a class library that I know will be used by websites and I need to access the config settings. I added a reference to System.Configuration, but I cannot find ConfigurationManager in the class library. A couple of things, one when I added a reference to the System.Configuration, it shows up as "System.configuration" with a lower case 'c', which I thought was odd. Another thing, when I access System.Configuration, the closest thing to ConfigurationManager is "ConfigurationSettings". I viewed the properties of the reference in a web app that allows me to use ConfigurationManager and this class library and they both point to the exact same file. Do I need to do this another way?

Here is a SS of my reference to it:

enter image description here

ScubaSteve
  • 7,724
  • 8
  • 52
  • 65
  • did you try to write Complete ConfigurationManager with case sensitive? – Faisal Hameed Mar 14 '15 at 19:03
  • In the code? Yes, it wanted me to generate the class. – ScubaSteve Mar 14 '15 at 19:34
  • 1
    @ScubaSteve Can try adding the following code in Member class? System.Configuration.ConfigurationManager.RefreshSection(""); Also, make sure that the project is targetting .NET 4.5.1 as this reference points to .NET 4.5.1 reference assemblies – Ganesh R. Mar 15 '15 at 04:30
  • Wow, thank you Ganesh. I forgot that my Interface to the repository was in the project Account. The actual concrete repository was in the EF proj right below it... Thanks for the virtual second pair of eyes. – ScubaSteve Mar 15 '15 at 04:57

3 Answers3

28

See https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager%28v=vs.100%29.aspx

It lies in System.Configuration namespace and assembly System.Configuration. Make sure you go to Framework tab in Add references and select System.Configuration Screenshot of Add Reference tab in Visual Studio 2013

Ganesh R.
  • 4,337
  • 3
  • 30
  • 46
13

As of Visual Studio Community 2017, I was not able to find the DLL using any of the methods that are listed here in this answer nor in any of the more antiquated responses on this site or others.

I had to find this NuGet package, which was a little nerve-wracking for me as I've never used NuGet, and then installed it using NuGet which is shipped with Visual studio.

You can install version 4.4.1 via the command line using:

Install-Package System.Configuration.ConfigurationManager -Version 4.4.1

Or, by searching for "System.Configuration.ConfigurationManager" in the Nuget Package Manager.

Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
Exho
  • 113
  • 2
  • 9
0

For me, I was getting this even with the reference added. I tried shutting everything down and re-opening the project and still it wouldn't resolve what I had typed in. Finally I just deleted my lines of code and typed in the fully qualified "System.Configuration.ConfigurationManager.AppSettings", and it "found itself". No real explanation for why that worked. It even figured out that the "using" reference at the top of the code was there so I didn't need to qualify it any longer. Weird!

I think it just comes down to some quirkiness in VS when doing some references. No real explanation to it.