“此方法已过时”尝试使用 App.config 文件时出现警告
这是我的方法:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
它位于 System.Configuration 命名空间中。尝试添加对 System.Configuration 程序集的引用。
System.Configuration.ConfigurationSettings
位于System
程序集中,这就是为什么您可以在不添加引用的情况下使用它。It is in the
System.Configuration
namespace. Try adding a reference to theSystem.Configuration
assembly.System.Configuration.ConfigurationSettings
is in theSystem
assembly, which is why you can use it without adding a reference.我有同样的问题。尝试使用
ConfigurationManager
而不是ConfigurationSettings
I had the same issue. Try
ConfigurationManager
instead ofConfigurationSettings
它位于
System.Configuration
。所以你应该能够看到它。
您是否缺少装配参考?
It is in
System.Configuration
.So you should be able to see it.
Are you missing the assembly reference?
将 System.Configuration.dll 添加到您的引用中
Add System.Configuration.dll to your references
您需要对项目中的
System.Configuartion.dll
库进行引用。然后你就可以使用它:You need a reference to the
System.Configuartion.dll
library in your project. Then you can use it:右键单击引用-->选择左侧的程序集-->查看
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 !