0

So in this particular C# helper, I have the following listed at the top of the file:

using System.Configuration;

When I try to reference it in the c# code (within the same file),

static readonly string apiKey = ConfigurationManager.AppSettings["apiKey"];

The name 'ConfigurationManager' does not exist in the current context.

Why would this be? System.Configuration is used all over the place in this application, but isn't being recognized in this particular file.

If I go to the Manage NuGet packages panel and search 'configuration manager', the top choice is 'System.Configuration.ConfigurationManager'. Even the oldest available version has a .NETFramework dependency of 4.6.1, whereas this application uses 4.5.1 so downloading it is not possible.

Is there something I am overlooking here?

Any and all input appreciated.

Nubtacular
  • 1,367
  • 2
  • 18
  • 38
  • 1
    Did you add a reference to the System.Configuration.dll in your references window? That class is in that assembly but the namespace is common to other system types – Steve Jun 27 '19 at 17:59
  • As for the references window, any time I go to 'Add References' I get `Error HRRESULT E_FAIL has been returned from a call to a COM Component`. It's VS2017, but have never been able to get rid of that error when trying to access the References panel. – Nubtacular Jun 27 '19 at 18:00
  • Sounds like you are missing a reference to System.Configuration.ConfigurationManager.dll – tolanj Jun 27 '19 at 18:01

1 Answers1

1

if you are getting error in the Add References window, try editing the .csproj to add the reference (along with other references) in the Reference ItemGroup like:

  <ItemGroup>
    <Reference Include="System.Configuration" />
  </ItemGroup>
Matt.G
  • 3,586
  • 2
  • 10
  • 23
  • Beautiful, that was the way to go. Updated vs2017 to latest version, deleted .vs folder, no dice. Opened up the .csproj for that particular Helper, added that `Reference Include=` line, and we're good to go. Thank you so much! – Nubtacular Jun 27 '19 at 19:11