C# &引用;这种方法已经过时了;尝试使用App.config文件时发出警告
以下是我的方法:C# &引用;这种方法已经过时了;尝试使用App.config文件时发出警告,c#,configurationmanager,C#,Configurationmanager,以下是我的方法: public IList<Member> FindAllMembers() { using (WebClient webClient = new WebClient()) { string htmlSource = webClient.DownloadString(ConfigurationSettings.AppSettings["MemberUrl"]); } XDocument response = XDocu
public IList<Member> FindAllMembers()
{
using (WebClient webClient = new WebClient())
{
string htmlSource = webClient.DownloadString(ConfigurationSettings.AppSettings["MemberUrl"]);
}
XDocument response = XDocument.Parse(htmlSource);
}
public IList FindAllMembers()
{
使用(WebClient WebClient=new WebClient())
{
字符串htmlSource=webClient.DownloadString(ConfigurationSettings.AppSettings[“MemberUrl]”);
}
XDocument response=XDocument.Parse(htmlSource);
}
建议我使用新的ConfigurationManager.AppSettings,但我在intellisense的任何地方都找不到它。我确信我正在导入正确的名称空间。我也需要参考一些东西吗
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);
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用系统文本;
使用System.Xml.Linq;
使用SharpDIC.Api.interface;
使用SharpDIC.Api.Models;
使用系统配置;
名称空间SharpDIC.Api.Concrete
{
类XmlMemberFinder:IMemberFinder
{
公共IList FindAllMembers()
{
使用(WebClient WebClient=new WebClient())
{
字符串htmlSource=webClient.DownloadString(ConfigurationSettings.AppSettings[“MemberUrl]”);
}
XDocument response=XDocument.Parse(htmlSource);
}
它在
所以你应该能看到它
是否缺少程序集引用?它位于
系统.Configuration
命名空间中。请尝试向系统.Configuration
程序集添加引用
System.Configuration.ConfigurationSettings
位于System
程序集中,因此您可以在不添加引用的情况下使用它。将System.Configuration.dll添加到引用中您需要项目中的System.configuation.dll
库的引用。然后您可以使用它:
string htmlSource = webClient.DownloadString(ConfigurationManager.AppSettings["MemberUrl"]);
我也有同样的问题。请尝试
ConfigurationManager
而不是ConfigurationSettings
右键单击参考-->选择左侧的程序集-->检查
System.Configuration.dll和System.Configuration.install.dll-->单击“确定”
希望这能解决我的问题!这很奇怪。在上面的代码中,我正确导入了名称空间,但仍然无法调用ConfigurationManager类。我将查看是否必须首先引用.NET库。