InvalidOperationException: Could not find 'UserSecretsIdAttribute' on assembly

后端 未结 3 592
Happy的楠姐
Happy的楠姐 2020-12-10 23:56

After deploying ASP.NET Core app to azure and opening the site, I get the following error:

InvalidOperationException: Could not find \'UserSecretsIdAt

3条回答
  •  盖世英雄少女心
    2020-12-11 00:48

    My .NET Core 3.* Worker Service required additional setup over a Web project.

    In Program.cs in the CreateHostBuilder method I needed this:

    .ConfigureAppConfiguration((ctx, builder) =>
                    {
                        // enable secrets in development
                        if (ctx.HostingEnvironment.IsDevelopment())
                        {
                            builder.AddUserSecrets();
                        }
                    })
    

    But (unlike my Web project) I explicitly needed to add this nuget package:

    install-package Microsoft.Extensions.Configuration.UserSecrets
    

    After that I could access the secrets.

提交回复
热议问题