在VS 2005中,经常会使用到ConfigurationSettings类来读取应用程序配置文件的信息,以获取数据库连接的字符串,但是,经常会出现如下的错误:
警告“System.Configuration.ConfigurationSettings.GetConfig(string)”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.GetSection”
警告 1 “System.Configuration.ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
解决方法:
首先添加对System.Configuration.dll 文件的引用,既在该项目中添加引用,在浏览中找到System.Configuration.dll文件,一般该文件在C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727文件夹中;
其次再把.net 1.0下的“System.Configuration.ConfigurationSettings.AppSettings”索引器换成.net 2.0下的“System.Configuration.ConfigurationManager.AppSettings”索引器。
把"System.Configuration.ConfigurationSettings.GetConfig换成System.Configuration.ConfigurationManager.GetSection
本文介绍了解决VS2005中ConfigurationSettings类读取配置文件时出现的过时警告的方法,包括替换为ConfigurationManager类及如何正确添加System.Configuration.dll引用。
984

被折叠的 条评论
为什么被折叠?



