[rc2] Fix AmbiguousMatchException when migration classes inherit DbContextAttribute#36666
Merged
AndriySvyryd merged 3 commits intorelease/10.0from Aug 28, 2025
Merged
[rc2] Fix AmbiguousMatchException when migration classes inherit DbContextAttribute#36666AndriySvyryd merged 3 commits intorelease/10.0from
AndriySvyryd merged 3 commits intorelease/10.0from
Conversation
…ses inherit DbContextAttribute Co-authored-by: AndriySvyryd <[email protected]>
Copilot
AI
changed the title
[WIP] Multiple custom attributes of the same type 'Microsoft.EntityFrameworkCore.Infrastructure.DbContextAttribute' found.
Fix AmbiguousMatchException when migration classes inherit DbContextAttribute
Aug 27, 2025
AndriySvyryd
approved these changes
Aug 27, 2025
Member
AndriySvyryd
left a comment
There was a problem hiding this comment.
@copilot Rewrite the PR summary using this template:
Fixes #{number}
**Description**
{Issue description}
**Customer impact**
{How does the reported issue affects customer's app? Are there workarounds?}
**How found**
{Was it customer reported or found during verification? How many customers are affected?}
**Regression**
{Is it a regression from a released version? Which one?}
**Testing**
{How the changes were tested}
**Risk**
{Low/Medium/High, argument why}
test/EFCore.Relational.Tests/Migrations/Internal/MigrationsAssemblyTest.cs
Show resolved
Hide resolved
Member
|
@copilot Continue |
Co-authored-by: AndriySvyryd <[email protected]>
Contributor
Author
... Rewrote the PR description using the requested template format, including sections for Description, Customer impact, How found, Regression, Testing, and Risk assessment. The updated description provides comprehensive details about the fix and its impact.
Completed both requested changes:
All tests are now passing and the changes have been committed. |
Copilot
AI
changed the title
[rc2] Fix AmbiguousMatchException when migration classes inherit DbContextAttribute
Fix AmbiguousMatchException when migration classes inherit DbContextAttribute
Aug 27, 2025
artl93
approved these changes
Aug 28, 2025
Member
artl93
left a comment
There was a problem hiding this comment.
Customer reported regression straightforward fix
roji
approved these changes
Aug 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #35590
Description
AmbiguousMatchExceptionis thrown when migration classes inherit from each other and both haveDbContextAttribute. The issue occurs becauseGetCustomAttribute<DbContextAttribute>()finds multiple attributes in the inheritance chain when using the default behavior that includes inherited attributes.Customer impact
Customers who create extended migrations that inherit from other migration classes and apply
DbContextAttributeto both the base and derived classes encounter a runtime exception during migration operations. This prevents normal migration operations from working.The workaround is to avoid using inheritance for migration classes (this isn't a common pattern) or to not apply
DbContextAttributeto base migration classes, but this limits code reuse.How found
Customer reported on EF9.
Regression
Yes, from EF8.
Testing
Test added.
Risk
Low. The change is surgical and only affects the specific attribute lookup behavior. This doesn't change any existing functionality for non-inheritance scenarios.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.