“此方法已过时”尝试使用 App.config 文件时出现警告

发布于 2024-10-08 14:20:01 字数 1051 浏览 5 评论 0原文

这是我的方法:

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

    XDocument response = XDocument.Parse(htmlSource);
}

建议我使用新的 ConfigurationManager.AppSettings,但我在智能感知中找不到它。我确信我正在导入正确的名称空间。我还需要参考一些东西吗?

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);
        }

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);
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

云淡风轻 2024-10-15 14:20:01

它位于 System.Configuration 命名空间中。尝试添加对 System.Configuration 程序集的引用。

System.Configuration.ConfigurationSettings 位于 System 程序集中,这就是为什么您可以在不添加引用的情况下使用它。

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.

刘备忘录 2024-10-15 14:20:01

我有同样的问题。尝试使用 ConfigurationManager 而不是 ConfigurationSettings

I had the same issue. Try ConfigurationManager instead of ConfigurationSettings

辞旧 2024-10-15 14:20:01

它位于 System.Configuration

所以你应该能够看到它。

您是否缺少装配参考?

It is in System.Configuration.

So you should be able to see it.

Are you missing the assembly reference?

柒七 2024-10-15 14:20:01

将 System.Configuration.dll 添加到您的引用中

Add System.Configuration.dll to your references

遥远的她 2024-10-15 14:20:01

您需要对项目中的 System.Configuartion.dll 库进行引用。然后你就可以使用它:

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

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"]);
因为看清所以看轻 2024-10-15 14:20:01

右键单击引用-->选择左侧的程序集-->查看
System.Configuration.dll和System.Configuration.install.dll-->单击“确定”。

希望这能解决我的问题!

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 !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文