【问题标题】:Cannot Solve "Configuration Does not Exist..." Error无法解决“配置不存在...”错误
【发布时间】:2020-11-23 22:36:14
【问题描述】:

我只是在尝试应用选项模式,并在 ConfigureServices 中对其进行了编码:

services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

但是 VS 给出错误“当前上下文中不存在名称配置。”

我添加了几乎所有的命名空间,例如 using System.Configuration 和 using Microsoft.Extensions.Configuration。关闭VS并再次打开它。删除代码并再次编码,但仍然出现相同的错误,并且配置始终以红色突出显示。

你知道这里发生了什么吗?

【问题讨论】:

  • 您需要添加字段或属性IConfiguration Configuration

标签: asp.net asp.net-core asp.net-web-api


【解决方案1】:

这里Configuration 是一个属性。你需要添加

private readonly IConfiguration Configuration { get; set;}

public Startup(IConfiguration configuration)
{
    Configuration = configuration;
}

【讨论】:

    猜你喜欢
    • 2015-12-07
    • 2022-10-06
    • 2020-07-03
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 2018-06-05
    相关资源
    最近更新 更多