开发者

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

开发者 https://www.devze.com 2023-01-31 15:51 出处:网络
Here\'s my method: public IList<Member> FindAllMembers() { using (WebClient webClient = new WebClient())

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 refere开发者_开发问答nce 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);
        }


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.


I had the same issue. Try ConfigurationManager instead of ConfigurationSettings


It is in System.Configuration.

So you should be able to see it.

Are you missing the assembly reference?


Add System.Configuration.dll to your references


You need a reference to the System.Configuartion.dll library in your project. Then you can use it:

string htmlSource = webClient.DownloadString(ConfigurationManager.AppSettings["MemberUrl"]);


Right click on references-->select Assemblies on left side--> Check System.Configuration.dll and System.Configuration.install.dll--> Click ok.

Hope this resolves the issue as mine !

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号