Skip to content

fix(migrator): resolve JwtOptions validation failure in Aspire orchestrator#1242

Merged
iammukeshm merged 2 commits into
fullstackhero:developfrom
cesarcastrocuba:fix/aspire-dbmigrator-startup
May 18, 2026
Merged

fix(migrator): resolve JwtOptions validation failure in Aspire orchestrator#1242
iammukeshm merged 2 commits into
fullstackhero:developfrom
cesarcastrocuba:fix/aspire-dbmigrator-startup

Conversation

@cesarcastrocuba
Copy link
Copy Markdown
Contributor

This PR fixes an issue where fsh-db-migrator silently crashes with OptionsValidationException when running via Aspire. In Aspire (dotnet run), the migrator's working directory is the project directory, so it fails to find appsettings.json (which is copied to the build output directory). Because IdentityModule registers JwtOptions with .ValidateOnStart(), the missing configuration causes the DI container build to fail entirely. Because AppHost.cs was recently updated to use .WaitForCompletion(migrator), this crash causes the fsh-api resource to wait indefinitely, hanging the entire Aspire orchestration. Fix: Explicitly load appsettings.json and appsettings.{Environment}.json from AppContext.BaseDirectory so that JwtOptions validation succeeds. Re-apply AddEnvironmentVariables() and AddCommandLine(args) immediately afterwards. This ensures that Aspire's dynamically injected environment variables maintain their intended priority and are not overridden by the hardcoded local connection strings in the loaded JSON files.

César Castro added 2 commits May 17, 2026 18:32
In local development (e.g. dotnet run or Aspire), the working directory
is the project folder where the linked appsettings.json doesn't exist natively.
This causes an OptionsValidationException for JwtOptions on startup, crashing
Aspire with exit code -532462766. Loading from AppContext.BaseDirectory
ensures the copied linked files are found.
…on in Aspire

When running DbMigrator via Aspire (dotnet run), the working directory is the project directory, so appsettings.json is not found. This causes JwtOptions to fail ValidateOnStart. We now load appsettings.json from AppContext.BaseDirectory, and re-apply environment variables so Aspire connection strings are not overwritten.
@iammukeshm iammukeshm merged commit 861381e into fullstackhero:develop May 18, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants