在VS2005|2008|2010中,经常会使用到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”
其实这是Framework 1.1 时代的写法。
解决方法如下:
添加对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