Search code examples
c#configurationmanager

"This method is obsolete" warning when trying to use App.config file


Here's my method:

public IList<Member> FindAllMembers()
{
    using (WebClient webClient = new WebClient())
    {
        string htmlSource = webClient.DownloadString(ConfigurationSettings.AppSettings["MemberUrl"]);
    }

    XDocument response = XDocument.Parse(htmlSource);
}

It's recommending I use the new ConfigurationManager.AppSettings, but I can't find it anywhere in intellisense. I'm sure I'm importing the correct namespaces. Do I need to reference something as well?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Xml.Linq;
using SharpDIC.Api.Interfaces;
using SharpDIC.Api.Models;
using System.Configuration;

namespace SharpDIC.Api.Concrete
{
    class XmlMemberFinder : IMemberFinder
    {
        public IList<Member> FindAllMembers()
        {
            using (WebClient webClient = new WebClient())
            {
                string htmlSource = webClient.DownloadString(ConfigurationSettings.AppSettings["MemberUrl"]);
            }

            XDocument response = XDocument.Parse(htmlSource);
        }

Solution

  • It is in the System.Configuration namespace. Try adding a reference to the System.Configuration assembly.

    System.Configuration.ConfigurationSettings is in the System assembly, which is why you can use it without adding a reference.