System.Configuration.ConfigurationSettings.GetConfig(string)”已过时 问题的解决方法
在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