ENGINEERING

Upgrading to .NET 10: check your EF Core migrations and your Npgsql metric names before you ship

.NET 8 goes out of support on November 10, 2026 (Microsoft’s support policy). RFF runs on it in two places: the API in the cloud, and the agent that runs as SYSTEM on your machines. I don’t want an unpatched runtime in either place, so we moved everything to .NET 10. It’s the current LTS and it’s supported until November 2028. We skipped .NET 9 because it’s a short-term release, and its support ends the same day as .NET 8’s.

Eight projects went from net8.0 to net10.0, the Microsoft.* and System.* packages went from 8.0.x to 10.0.14, Npgsql’s EF Core provider went to 10.0.3, and the Dockerfile and CI moved to the 10.0 images. It compiled on the first try with no errors. Then the test suite ran, and three of its 3,770 tests failed.

EF Core 9+ throws on a stale migrations snapshot

Two of the failures were the same exception:

System.InvalidOperationException: An error was generated for warning
'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning':
The model for context 'AppDbContext' has pending changes.
Add a new migration before updating the database.

Starting with EF Core 9, Database.Migrate() compares your model to the migrations snapshot, and if they differ it throws (EF Core 9 breaking changes). On .NET 8 it just ran the migrations.

Our snapshot is stale on purpose. We don’t ship schema changes as generated migrations, because one once tried to re-create tables that already existed in production. New tables and columns go in an idempotent SQL script (ADD COLUMN IF NOT EXISTS and friends) that runs on every startup. So our model always differs from the snapshot, and the API calls MigrateAsync() on every boot. Every deploy after the upgrade would have failed at startup.

Microsoft’s own mitigation for this case is to ignore the warning:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) =>
    optionsBuilder.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning));

Put it in the DbContext, not in Program.cs. Our tests build the context a dozen different ways, and OnConfiguring is the one place all of them go through. If you add it only where you register the context, the app starts and the tests still fail.

If you don’t manage schema outside migrations and you see this warning, don’t suppress it. It means a migration is missing.

Npgsql 10 renamed its connection pool metrics

The third failure was one line:

PoolPressureReaderTests.Reader_Sees_Busy_Connections_And_The_Max
  used=0

The API has a watchdog that warns when the Postgres connection pool is close to full. We added it the day after a pool-exhaustion outage in October. It reads Npgsql’s own metrics through a MeterListener and matches the instruments by name: db.client.connections.usage and db.client.connections.max.

Npgsql 10 moved its metrics to the OpenTelemetry semantic conventions (Npgsql 10 release notes). The instruments are now db.client.connection.count and db.client.connection.max, and the tag that says whether a connection is in use went from state to db.client.connection.state. Nothing throws and nothing logs. The listener never matches anything, and the alarm reads zero, which looks exactly like a healthy pool.

That test caught it because it opens four real connections against a real Postgres and checks the reader sees them. A test that only checked the reader doesn’t throw would have passed. The reader now listens for both the old and the new names.

If you read Npgsql metrics anywhere (a MeterListener, an OpenTelemetry dashboard, an alert rule on db.client.connections.usage), check it after the upgrade.

Smaller changes

The agent

The API is easy to roll back. The agent runs unattended on machines nobody can walk over to, so I went through the .NET 10 breaking changes for the ones that hit an app like it:

Then I ran it on lab machines:

The API image also started cleanly on both a fresh Postgres and one that was already migrated, which is the case that matters in production.

What to check before you upgrade

  1. Run your app’s real startup path against a real database, not just unit tests. If you call Migrate() and keep schema anywhere besides EF migrations, expect PendingModelChangesWarning.
  2. Search for db.client.connections in your code, dashboards and alert rules if you use Npgsql.
  3. Build with warnings visible and read the new SYSLIB and ASPDEPR ones.
  4. If you ship self-contained or single-file apps, check the publish output for native DLLs next to the exe, and whether your Linux or macOS service handles SIGTERM itself.
  5. Check your fleet’s OS versions against the .NET 10 supported list.

Doing it with RFF

The RFF agent ships with its own runtime, so moving it to .NET 10 doesn’t mean installing .NET on your machines. The new agent rolls out through RFF’s normal agent updates: a signed build, a soak on our lab machines, then a staged rollout. Nothing changes on your side.

RFF is free for your first 100 endpoints: getrff.com.

Sources

One email per new post, nothing else. Unsubscribe in one click. Or use the RSS feed.

Comments

Comments use GitHub Discussions, so you'll need a GitHub account to post. Corrections are especially welcome.