'System.Configuration.ConfigurationSettings.AppSettings'已过时

001*_*001 53 c# class-library class visual-studio

我收到了以下警告

'System.Configuration.ConfigurationSettings.AppSettings'已过时:''此方法已过时,已被System.Configuration取代!System.Configuration.ConfigurationManager.AppSettings"'

你是如何解决的?

Mik*_*eel 109

添加对程序集的引用System.Configuration.

然后在顶部(假设C#)使用System.Configuration(在VB.NET中导入System.Configuration).

使用ConfigurationManager.AppSettings["MySetting"]访问设置!


sta*_*k72 28

作为一个警告我不认为重要,除非你已经关闭一个治疗警告作为错误设置

添加对System.Configuration的引用

您所要做的就是更新到最新的代码,以便您使用 ConfigurationSettings.AppSettings[""] change to ConfigurationManager.AppSettings[""]

这应该工作

  • 添加对system.Configuration的引用,然后它将工作 - 生病了更新我的答案 (2认同)
  • 添加ref后,找不到configurationManager :-( (2认同)

mat*_*aly 15

以防其他人在寻找" 添加引用"选项以在Visual Studio 2010中实现接受的答案.(我必须在更新VB项目时这样做).

在Visual Studio 2010中:

  1. 单击Project> Add Reference.
  2. 单击C#选项卡(即使我的是一个纯VB项目)
  3. 向下滚动一半以找到System.Configuration(因为.NET Framework 4.0是所选版本,所以我有v4)
  4. 单击"确定",然后根据给出的建议更新代码行.

从System.Configuration.Configuration 设置 .AppSettings("name")到System.Configuration.Configuration Manager .AppSettings

在不添加引用的情况下,IntelliSense在您键入时不会建议ConfigurationManager,这是因为它没有引用来了解它的位置.这也是为什么在根据他们的建议更新代码行时会出现错误的原因.


小智 5

System.configuration DLL exsit在c:\ Windows\Microsoft.NET\Framework\v2.0.50727 \