I'm using dotnet-user-secrets with an ASP.NET Core 2.1.4 app.
To be clear, this question is about invoking dotnet run
from the command line in macOS; this issue does not exist when invoking dotnet run
for the same application in Windows. Additionally, running the app from within Visual Studio works as expected on both macOS and Windows.
Typing dotnet user-secrets list
at the command line returns the expected output:
TokenProviderOptions:SecretKey = …
TokenProviderOptions:Issuer = …
TokenProviderOptions:Audience = …
I can also access the secrets.json
file in the ~/.microsoft/usersecrets/<userSecretsId>
folder as expected:
{
"TokenProviderOptions": {
"SecretKey": "…",
"Issuer": "…",
"Audience": "…"
}
}
Here is how I am accessing the secrets inside Startup.cs
:
// Configure tokens
var tokenOptions = Configuration
.GetSection("TokenProviderOptions")
.GetChildren()
.ToList();
string
secretKey = tokenOptions.Single(x => x.Key.Equals("SecretKey")).Value,
issuer = tokenOptions.Single(x => x.Key.Equals("Issuer")).Value,
audience = tokenOptions.Single(x => x.Key.Equals("Audience")).Value;
As I mentioned before, this runs with no problems from Command Prompt and Visual Studio in Windows. And, from Visual Studio in macOS, I can debug and see the tokenOptions
list with the three items. However, when I type dotnet run
in Terminal, I get this error at the first .Single()
:
System.InvalidOperationException: Sequence contains no matching element
Is there an extra step I'm missing to run this successfully from the command line in macOS?