C
C#6d ago
Angius

Aspire user secrets not available in prod environment

I created a prod profile in launchsettings of my apphost:
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"dev": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17226;http://localhost:15203",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21252",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22080"
}
},
"prod": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17226;http://localhost:15203",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production",
"DOTNET_ENVIRONMENT": "Production",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21252",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22080"
}
}
}
}
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"dev": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17226;http://localhost:15203",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21252",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22080"
}
},
"prod": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17226;http://localhost:15203",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production",
"DOTNET_ENVIRONMENT": "Production",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21252",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22080"
}
}
}
}
and everything works when I run the dev profile, but prod profile throws
Unhandled exception. Aspire.Hosting.DistributedApplicationException: Parameter resource could not be used because configuration key 'Parameters:postgres-username' is missing and the Parameter has no default value.
Unhandled exception. Aspire.Hosting.DistributedApplicationException: Parameter resource could not be used because configuration key 'Parameters:postgres-username' is missing and the Parameter has no default value.
at me, on the last line here
var builder = DistributedApplication.CreateBuilder(args);

var sqlPassword = builder.AddParameter("postgres-password", secret: true);
var sqlUsername = builder.AddParameter("postgres-username", secret: true);

Console.WriteLine($"{sqlUsername.Resource.Value} / {sqlPassword.Resource.Value}");
var builder = DistributedApplication.CreateBuilder(args);

var sqlPassword = builder.AddParameter("postgres-password", secret: true);
var sqlUsername = builder.AddParameter("postgres-username", secret: true);

Console.WriteLine($"{sqlUsername.Resource.Value} / {sqlPassword.Resource.Value}");
Those values come from usersecrets, could that be the issue?
3 Replies
Sehra
Sehra6d ago
user secrets is only added as a configuration source in development
Angius
AngiusOP6d ago
So even if I run the prod profile on my local machine, it's just not gonna grab user secrets? Fair enough, I guess. I'll have to figure out where to put them now lol
Unknown User
Unknown User5d ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?