c# - ConfigurationSettings.AppSettings 已过时

标签 c# methods obsolete

<分区>

下面的代码工作正常:

string api_url = ConfigurationSettings.AppSettings["api-url"].ToString();

警告信息如下:

'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: '"This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings"'

根据警告消息的建议,我尝试将 ConfigurationSettings.AppSettings 替换为 ConfigurationManager.AppSettings

string api_url = ConfigurationManager.AppSettings["api-url"].ToString();

现在出现一条错误消息,指出:

The name 'ConfigurationManager' does not exist in the current context

这些是导入的命名空间:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

请帮帮我。

最佳答案

不仅需要在ConfigurationManager.AppSettings["api-url"].ToString();前面加上System.Configuration还得加上对程序集 System.Configuration.dll 的引用。

这是类似问题的链接 The name 'ConfigurationManager' does not exist in the current context

关于c# - ConfigurationSettings.AppSettings 已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15589129/

相关文章:

c# - Xml 架构规范是否定义了具有默认值的可选属性的序列化?

c# - 作为方法调用参数的函数

java - 如何获取 argument.nameOfTheMethod() 中参数的值?

c# - 使用 C# 合并具有相同名称的文件夹或子文件夹

javascript - 未捕获的类型错误 : NaN JavaScript Sharepoint

c# - 如何将程序集标记为过时

obsolete - 当我知道的东西死了时我该怎么办?

ios - 单点触控 : Approaching Obsolete iOS methods

c# - MigraDoc - 获取部分的高度

python - 矩阵类方法中的参数错误 - Python