[release/10.0] Fix NullReferenceException in dbcontext optimize with cross-version compatibility#37547
[release/10.0] Fix NullReferenceException in dbcontext optimize with cross-version compatibility#37547Copilot wants to merge 2 commits intorelease/10.0from
Conversation
… null Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
|
@copilot Update progress by rewriting the PR summary using this template: |
... Updated the PR description with the structured template. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a NullReferenceException in the dotnet ef dbcontext optimize command when using dotnet-ef tools version 9.0+ with EF Core 8.0 projects. The issue occurs because DbContextOperations.Optimize changed its return type from void (8.0) to IReadOnlyList<string> (9.0+), causing the tools to receive a null result when operating on EF Core 8.0 projects. The fix adds a null check before attempting to report results.
Changes:
- Added null check before calling
ReportResultsinDbContextOptimizeCommand.Executeto handle cross-version compatibility
artl93
left a comment
There was a problem hiding this comment.
Regression, customer reported, non-obvious workaround, approved.
Fixes #36437
Description
The
dotnet ef dbcontext optimizecommand throws aNullReferenceExceptionwhen using dotnet-ef tools version 9.0 or later with EF Core 8.0 projects, despite successfully generating the compiled model.Customer impact
When customers use dotnet-ef tools 9.0+ with EF Core 8.0 projects and run
dotnet ef dbcontext optimize, they see aNullReferenceExceptionerror message after the compiled model is successfully generated. The error appears atDbContextOptimizeCommand.ReportResults(IEnumerable<string> generatedFiles)when attempting to iterate over a null result.While the compiled model files are still created correctly, the error message can be confusing and may cause build pipeline failures if not handled properly.
Workaround: Customers can either:
How found
Multiple customer reports on EF 9.0.x and 10.0.x
Regression
Yes, introduced in #33028 (part of #24894). The issue occurs because:
Testing
Verified manually
Risk
Low. The change is minimal (3-line addition).
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.