16

The following code works fine:

string api_url = ConfigurationSettings.AppSettings["api-url"].ToString();

with a warning message as follows:

'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: '"This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings"'

As suggested by the warning message, I tried replacing ConfigurationSettings.AppSettings with ConfigurationManager.AppSettings

string api_url = ConfigurationManager.AppSettings["api-url"].ToString();

Now an error message appears, stating:

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

These are the namespaces imported:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

Please help me.

DarkAjax
  • 15,955
  • 11
  • 53
  • 65
Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89

3 Answers3

34

Not only do you need to add System.Configuration in front of ConfigurationManager.AppSettings["api-url"].ToString(); you also have to add the reference to the assembly System.Configuration.dll.

Here is link to similar question The name 'ConfigurationManager' does not exist in the current context

Community
  • 1
  • 1
Vortex
  • 663
  • 6
  • 7
3

Add a reference to System.Configuration. The deprecated one was in System.dll but the same namespace System.Configuration

manojlds
  • 290,304
  • 63
  • 469
  • 417
2

Add reference to System.Configuration.

Nick Binnet
  • 1,910
  • 7
  • 33
  • 49