Skip to content

Check the EF Core major in the differ and generator constructors - #103

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/91-guard-in-constructors
Oct 20, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/91-guard-in-constructors

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #91

Problem

The EF Core major guard (#55) runs in every registration entry point, but the differs and the Npgsql SQL generator are public types. An application that registers one itself, e.g. optionsBuilder.ReplaceService<IMigrationsModelDiffer, CustomMigrationsModelDiffer>(), passes no entry point: on EF Core 11 rc.2 the differ constructs, and the first GetDifferences fails with MissingMethodException: …IIndex.get_Properties(), which names neither the cause nor the successor package.

Change

  • EfCoreVersionGuard.Guarded(argument): runs ThrowIfUnsupported() and returns its argument, so a primary constructor can run the check on its way to the base constructor (before EF's own constructor runs).
  • CustomMigrationsModelDiffer passes its first base argument through it. The PostgreSQL and SQL Server differs construct the core one, so the one call covers all three; NpgsqlComplexIndexMigrationsModelDiffer.cs is untouched (stream B owns it).
  • NpgsqlComplexIndexSqlGenerator does the same.
  • docs/upgrading.md: the EF Core 11 section says the hand-registered differs and generator check too.

No changelog line: the guard is new in 5.5.0, and CONTRIBUTING.md leaves out fixes to something new in the same release. The 5.5.0 Breaking line already says every registration route throws.

Tests

EfCoreVersionGuardTests gains four rows, one per hand registration: ReplaceService for each of the three differs and for the Npgsql generator, resolved from a context with service-provider caching off, so no cached instance can pass a row without constructing it. With EF Core 11 fed they throw the guard's message, and with EF Core 10 they resolve.

Verified by reverting: with both Guarded calls removed, the four new rows fail and the other 29 pass. Full unit suite: 395 passed.

🤖 Generated with Claude Code

…#91)

The major guard ran in every registration entry point, but the differs and
the Npgsql SQL generator are public types an application can register
itself: ReplaceService<IMigrationsModelDiffer, CustomMigrationsModelDiffer>()
constructed the differ on EF Core 11 rc.2, and the first GetDifferences
failed with MissingMethodException: IIndex.get_Properties(), naming nothing.

The core differ and the Npgsql generator now run the check on their way to
the base constructor (EfCoreVersionGuard.Guarded). The PostgreSQL and SQL
Server differs construct the core one, so they are covered by the same call.

Verified: EfCoreVersionGuardTests gains a row per hand registration (the
three differs and the generator, each resolved from a fresh service
provider); with both Guarded calls reverted, those four rows fail.

No changelog line: the guard is new in 5.5.0 (#55).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/migrations The differs, snapshot format, EnsureCreated and design-time wiring bug Something isn't working package/core Affects EFCore.ComplexIndexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL package/sqlserver Affects EFCore.ComplexIndexes.SqlServer severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EF Core major guard: registering the differ by hand bypasses it and fails with MissingMethodException

1 participant