Document null connection string guard for PublishAsMigrationBundle with Azure Postgres - #17856
Document null connection string guard for PublishAsMigrationBundle with Azure Postgres#17856Andriy Svyryd (AndriySvyryd) with Copilot wants to merge 9 commits into
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds troubleshooting guidance to the EntityFrameworkCore hosting integration documentation to address PublishAsMigrationBundle failures when EF Core design-time tooling instantiates a DbContext while only a publish-time placeholder connection string is available.
Changes:
- Documented why design-time
DbContextcreation during migration bundle generation can fail when providers eagerly parse connection strings (example:EnrichAzureNpgsqlDbContext). - Added a recommended
EF.IsDesignTimeguard pattern to avoid design-time connection-string parsing while still receiving the real connection string at runtime via--connection.
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17856Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17856" |
…tation section Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
|
Waleed Khaled (@Waleed-KH) Good point. Instead of Copilot Change the readme accordingly |
…ADME example Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Updated in the latest commit. The example now reads the connection string once up front and gates both |
|
Andriy Svyryd (@AndriySvyryd) Now the publish is failing again 🤣. After doing further checks, I discovered that the migration bundle can be generated without any problems even when the To fix this, I believe it would be better if Aspire do not pass any connection string when running the generate migration bundle command during publish, allowing it to function correctly without requiring any checks from the user-side. |
|
I see, #17905 should take care of that |

Description
PublishAsMigrationBundlefails duringaspire publishwhen theDbContextusesEnrichAzureNpgsqlDbContext, withFormat of the initialization string does not conform to specification starting at index 0.The
*-generate-migration-bundlestep runsdotnet ef migrations bundle, which creates theDbContextat design time to discover the model. The EF tool resource inherits the project'sWithReference(<db>)wiring, soConnectionStrings__<db>is set to a publish-time placeholder expression.EnrichAzureNpgsqlDbContextconfigures an Entra ID data source that parses that string eagerly during context creation, andNpgsqlConnectionStringBuilderthrows. The bundle never needs a real connection string at design time — it receives one at run time via the--connectionargument Aspire injects — so the fix lives in user code: guard connection-string-dependent configuration by checking whether the connection string isnull.These are documentation-only changes (no product code change required, since the bundle is configured correctly at run time).
README.md: adds a "Troubleshooting: design-time connection strings" subsection under Publishing Support with an inline null-check example, replaces the "Additional documentation" placeholder link with the published EF migrations page (https://aspire.dev/integrations/databases/efcore/migrations/#automated-ef-migrations-with-addefmigrations), and removes the generichttps://learn.microsoft.com/dotnet/aspire/link.Recommended user-side fix:
The same pattern applies to any provider that parses the connection string while the
DbContextis being created.Checklist
<remarks />and<code />elements on your triple slash comments?