From 3411e6ec6550bc4027cfe9a48d8d74bda93843d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Castro?= Date: Sun, 17 May 2026 18:32:16 +0200 Subject: [PATCH 1/2] fix(migrator): load appsettings.json from BaseDirectory for local dev 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. --- src/Host/FSH.Starter.DbMigrator/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Host/FSH.Starter.DbMigrator/Program.cs b/src/Host/FSH.Starter.DbMigrator/Program.cs index 3779e3a46d..f5f51ca523 100644 --- a/src/Host/FSH.Starter.DbMigrator/Program.cs +++ b/src/Host/FSH.Starter.DbMigrator/Program.cs @@ -49,6 +49,12 @@ var builder = Host.CreateApplicationBuilder(args); +// In local development (dotnet run), the working directory is the project folder, +// but appsettings.json is linked and copied to the output directory. +// We explicitly load it from AppContext.BaseDirectory so IdentityModule's JwtOptions validate. +builder.Configuration.AddJsonFile(Path.Combine(AppContext.BaseDirectory, "appsettings.json"), optional: true); +builder.Configuration.AddJsonFile(Path.Combine(AppContext.BaseDirectory, $"appsettings.{builder.Environment.EnvironmentName}.json"), optional: true); + // Fail-fast before option-validation runs at host build time: if the operator // forgot to set DatabaseOptions__ConnectionString, give them a single clear // line they'll actually read rather than a validation exception stack trace. From 812d554d3b36e1f5779894d095c49bbb4924586b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Castro?= Date: Sun, 17 May 2026 20:35:30 +0200 Subject: [PATCH 2/2] fix(migrator): explicitly load appsettings to fix JwtOptions validation 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. --- src/Host/FSH.Starter.DbMigrator/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Host/FSH.Starter.DbMigrator/Program.cs b/src/Host/FSH.Starter.DbMigrator/Program.cs index f5f51ca523..9f1f9c53a7 100644 --- a/src/Host/FSH.Starter.DbMigrator/Program.cs +++ b/src/Host/FSH.Starter.DbMigrator/Program.cs @@ -46,7 +46,6 @@ await Console.Out.WriteLineAsync(MigratorCommand.HelpText).ConfigureAwait(false); return 0; } - var builder = Host.CreateApplicationBuilder(args); // In local development (dotnet run), the working directory is the project folder, @@ -55,6 +54,10 @@ builder.Configuration.AddJsonFile(Path.Combine(AppContext.BaseDirectory, "appsettings.json"), optional: true); builder.Configuration.AddJsonFile(Path.Combine(AppContext.BaseDirectory, $"appsettings.{builder.Environment.EnvironmentName}.json"), optional: true); +// Re-add environment variables and command line args so they maintain priority over the manually added JSON files. +builder.Configuration.AddEnvironmentVariables(); +builder.Configuration.AddCommandLine(args); + // Fail-fast before option-validation runs at host build time: if the operator // forgot to set DatabaseOptions__ConnectionString, give them a single clear // line they'll actually read rather than a validation exception stack trace.