Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 27, 2025

Fixes #35590

Description
AmbiguousMatchException is thrown when migration classes inherit from each other and both have DbContextAttribute. The issue occurs because GetCustomAttribute<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 DbContextAttribute to 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 DbContextAttribute to 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.

…ses inherit DbContextAttribute

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
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
Copilot AI requested a review from AndriySvyryd August 27, 2025 01:42
Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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}

@AndriySvyryd
Copy link
Member

@copilot Continue

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 27, 2025

@copilot Rewrite the PR summary using this template:

...

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.

@copilot Continue

Completed both requested changes:

  1. Rewrote the PR description using the template format with all required sections
  2. Fixed the test by updating the assertion from 2 to 3 migrations to account for the new BaseMigration class

All tests are now passing and the changes have been committed.

@AndriySvyryd AndriySvyryd changed the title Fix AmbiguousMatchException when migration classes inherit DbContextAttribute [rc2] Fix AmbiguousMatchException when migration classes inherit DbContextAttribute Aug 27, 2025
Copilot AI changed the title [rc2] Fix AmbiguousMatchException when migration classes inherit DbContextAttribute Fix AmbiguousMatchException when migration classes inherit DbContextAttribute Aug 27, 2025
Copilot AI requested a review from AndriySvyryd August 27, 2025 22:43
@AndriySvyryd AndriySvyryd changed the title Fix AmbiguousMatchException when migration classes inherit DbContextAttribute [rc2] Fix AmbiguousMatchException when migration classes inherit DbContextAttribute Aug 27, 2025
@AndriySvyryd AndriySvyryd marked this pull request as ready for review August 27, 2025 22:47
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner August 27, 2025 22:47
@AndriySvyryd AndriySvyryd requested a review from artl93 August 27, 2025 22:47
Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Customer reported regression straightforward fix

@AndriySvyryd AndriySvyryd merged commit f3ddac4 into release/10.0 Aug 28, 2025
8 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-35590 branch August 28, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple custom attributes of the same type 'Microsoft.EntityFrameworkCore.Infrastructure.DbContextAttribute' found.

4 participants