读取xml文件时提示错误

tslt65 2013-03-27 03:37:06
读取xml文件时提示错误
xml文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="HostInfo" type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<HostInfo hostname="localhost" port="6800" />
</configuration>

控制台文件:
class Program
{
static void Main(string[] args)
{
IDictionary HostSetings = (IDictionary)ConfigurationSettings.GetConfig("HostInfo");
}
}

使用visual studio2008,生成文件时提示错误:
警告 4 “System.Configuration.ConfigurationSettings.GetConfig(string)”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.GetSection”

是不是先要确定xml文件的位置?不何如何更改,求教,谢谢
...全文
201 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tslt65 2013-03-27
  • 打赏
  • 举报
回复
楼上,我已在文件的顶部导入了System.Configuration,还是提示出错。 现在发现的问题所在了,同时要在解决方案资源管理器窗口的引用文件夹里导入System.Configuration才行,大家以后注意了。
bdmh 2013-03-27
  • 打赏
  • 举报
回复
方法已经不提倡在用了,告诉你用新方法
DENQH 2013-03-27
  • 打赏
  • 举报
回复
这个ConfigurationSettings已过时了,不再用了,添加Configuration引用再用ConfigurationManager来读取

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧