I follow this tutorial: https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1&tabs=windows#access-a-secret
To a .NET Core 3.1 project I've added Microsoft.Extensions.Configuration.UserSecrets package, I have clicked on the project to manage secrets, the file has been created in the AppData directory and the UserSecretsId has been added automatically in .csproj file.
Because the Host.CreateDefaultBuilder didn't load secrets I decided to add them manually
if (hostContext.HostingEnvironment.IsDevelopment())
{
builder.AddUserSecrets(Assembly.GetExecutingAssembly());
}
})
.Build();
But then I get
System.InvalidOperationException
HResult=0x80131509
Message=Could not find 'UserSecretsIdAttribute' on assembly 'XXX'.
Check that the project for 'XXX' has set the 'UserSecretsId' build property.
If the 'UserSecretsId' property is already set then add a reference to the Microsoft.Extensions.Configuration.UserSecrets package.
Source=Microsoft.Extensions.Configuration.UserSecrets
I've checked the suggestion in the expecion's description and both predicaments are fulfilled.