Closed
Description
Overview
The logic that injects the UserSecretsIdAttribute
appears to only work if the Microsoft.Extensions.Configuration.UserSecrets
package is reference directly (or through the ASP.NET Core runtime). The worker template references it transitively through Microsoft.Extensions.Hosting
and the attribute is never generated and user secrets are not loaded.
This was originally reported by customers: dotnet/extensions#2743 dotnet/AspNetCore.Docs#14315
Repro Steps
Repro repo (just clone and skip to step 3): https://github.com/anurse/UserSecretsInWorkerRepro
dotnet new worker
- Edit
ExecuteAsync
inWorker.cs
to the following
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
_logger.LogInformation("The secret is: {Secret}", _config["SecretName"]);
await Task.Delay(1000, stoppingToken);
}
}
- Set a user secret value:
dotnet user-secrets set "SecretName" "SecretValue"
- Run with
dotnet run
Expected Results
The secret value is written in a log message like:
info: UserSecretsInWorkerRepro.Worker[0]
Worker running at: 12/05/2019 11:51:07 -08:00
info: UserSecretsInWorkerRepro.Worker[0]
The secret is: SecretValue
Actual Results
The secret value is not present
info: UserSecretsInWorkerRepro.Worker[0]
Worker running at: 12/05/2019 11:51:07 -08:00
info: UserSecretsInWorkerRepro.Worker[0]
The secret is: (null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels