skip to content

Moving an ASP.NET Core web API from .NET 8 to 10, which 9.0 and 10.0 changes tend to bite, and how do you catch them before production does?

level: seniorimportance: should knowfreq 40%

answer

  1. binary, source and behavioural breaks
  2. ASPDEPR ids mark obsolete APIs
  3. behavioural changes compile silently
  4. cookie auth: 401/403 for API endpoints
  5. handled exceptions no longer logged

basics

~20 s

Obsoletions announce themselves as ASPDEPR build warnings, but behavioural changes compile silently: cookie auth answering API endpoints with 401/403, IExceptionHandler-handled exceptions no longer logged, OpenAPI 3.1 documents. Read the 9 and 10 breaking-change lists and cover them with tests.

solid answer

~50 s

Microsoft classifies each breaking change as binary, source or behavioural, and only the first two show up at build time. In ASP.NET Core 10 the source-level ones are obsoletions with `ASPDEPR` ids: `WithOpenApi()` (`ASPDEPR002`), Razor runtime compilation (`ASPDEPR003`), `WebHostBuilder` (`ASPDEPR004`), `KnownNetworks` (`ASPDEPR005`), `IActionContextAccessor` (`ASPDEPR006`) and `WebHost` (`ASPDEPR008`). The behavioural ones need tests: cookie authentication now returns 401 or 403 to known API endpoints instead of redirecting, the exception handler middleware stops logging exceptions an `IExceptionHandler` handled, and the OpenAPI document defaults to 3.1 on Microsoft.OpenApi 2.0. From 9 you inherit changes such as middleware with two satisfiable constructors failing activation and a plain `HostBuilder` validating DI scopes in Development. So: read both lists, make the obsolescence warnings visible or fatal, and add integration tests that pin status codes, logs and the OpenAPI document before deploying.

code

csharp · 20 lines
csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi(options =>
{
    // Keep a 3.0 document while client generators catch up with 3.1
    options.OpenApiVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0;
});
builder.Services.AddProblemDetails();
builder.Services.AddExceptionHandler<ReservationExceptionHandler>();

var app = builder.Build();

app.UseExceptionHandler(new ExceptionHandlerOptions
{
    // .NET 10 stops logging exceptions an IExceptionHandler handled; keep them
    SuppressDiagnosticsCallback = _ => false
});

app.MapOpenApi();
app.Run();

go deeper

for a junior

Know that each release publishes a breaking-change list and that obsolete APIs show up as ASPDEPR warnings.

for a middle

Name the 10.0 changes that affect web APIs, cookie redirects, exception diagnostics and OpenAPI 3.1, and their opt-outs.

for a senior

Turn the 9 and 10 lists into tests that pin status codes, logs and the OpenAPI document, and stage the rollout.

for a principal

Set a rule for opt-out switches: allowed as bridges with an owner and a removal date, never as permanent configuration.

## Three kinds of breaking change The .NET breaking-change pages tag every entry with a category, and the category decides how you find it. | Category | What breaks | How it shows up | |---|---|---| | **Binary incompatible** | existing binaries fail to load or run against the new version | runtime failures, usually from older packages | | **Source incompatible** | code no longer compiles, or compiles with a new warning | the build: errors, or warnings such as `ASPDEPR002` | | **Behavioural** | the same code does something different | nothing at build time; only tests or production | An 8-to-10 upgrade has to read the ASP.NET Core breaking-change pages for **both** 9 and 10, because each list is relative to the previous release. ## The 10.0 changes that bite web APIs | Change | Before | In 10 | Way back | |---|---|---|---| | Cookie auth on API endpoints | redirect to the login page (non-XHR) | 401 / 403 for known API endpoints | `Microsoft.AspNetCore.Authentication.Cookies.IgnoreRedirectMetadata` switch | | Exception handler diagnostics | handled exceptions logged and counted | not logged when `IExceptionHandler.TryHandleAsync` returns true | `ExceptionHandlerOptions.SuppressDiagnosticsCallback` | | OpenAPI document | 3.0 | 3.1 by default, on Microsoft.OpenApi 2.0 | `OpenApiOptions.OpenApiVersion` | | `WithOpenApi()` | supported | obsolete, `ASPDEPR002` | remove it; metadata flows without it | | `WebHostBuilder`, `WebHost` | supported | obsolete, `ASPDEPR004`, `ASPDEPR008` | move to `WebApplication` or `HostBuilder` | | `ForwardedHeadersOptions.KnownNetworks` | supported | obsolete, `ASPDEPR005` | `KnownIPNetworks` | The first two are the dangerous ones because they are silent. A SPA or monitoring probe that expected a 302 now gets a 401; a dashboard that counted handled exceptions goes quiet, which looks like an improvement until someone needs the data. The OpenAPI change breaks document and schema transformers written against Microsoft.OpenApi 1.x even if you pin the 3.0 output, and changes how nullable types appear for client generators. Outside ASP.NET Core itself, .NET 10 also binds `null` configuration values instead of treating them as missing, runs `BackgroundService.ExecuteAsync` entirely on a background thread, and makes Ubuntu the default for the official container images. ## The 9.0 changes you inherit - A middleware class with two constructors that DI can both satisfy no longer silently picks the longer one; activation fails until you mark one with `[ActivatorUtilitiesConstructor]`. - A plain `HostBuilder` that never configured its service provider now turns on `ValidateScopes` and `ValidateOnBuild` in Development, surfacing captive dependencies there; `Host.CreateDefaultBuilder` and `WebApplication` already did this. - The Forwarded Headers middleware ignores `X-Forwarded-*` from proxies not listed as known, a change also shipped in 8.0.17. - Swashbuckle left the project templates in favour of `AddOpenApi()` and `MapOpenApi()`; existing apps keep working, but new services start differently. ## How to catch them 1. **Read both lists** before the work starts and turn every relevant entry into a ticket with an owner. 2. **Make obsolescence visible.** Build with warnings shown in CI, and for the `ASPDEPR` ids you have cleared, promote them to errors so they cannot return. 3. **Pin behaviour with integration tests.** Assert the status code an anonymous call to an API endpoint gets, that a handled exception still produces the log or metric your alerts rely on, and snapshot the OpenAPI document so a version or shape change fails a test, not a client. 4. **Roll out in stages.** Ship to a staging slot or a fraction of traffic first and compare error rates, status-code mixes and log volumes with the old build. ## Opt out or adapt Each behavioural change ships with a way back, and using one is legitimate as a bridge. Record it as debt with a date: the opt-outs exist so that teams can upgrade the runtime first and adapt behaviour second, not so that .NET 8 behaviour lives on indefinitely.

  • Why can an app that builds cleanly on .NET 10 still behave differently from its .NET 8 build?
    Because behavioural breaking changes alter what existing code does without any compiler signal: the same cookie-auth setup now answers API endpoints with 401, the same IExceptionHandler now suppresses logging, the same AddOpenApi call now emits 3.1. Only tests, staged rollout or reading the breaking-change lists catch those.
  • Is it safe to leave ASPDEPR warnings in place after the upgrade?
    For a while: the APIs are obsolete, not removed, and still work in 10. But obsolete APIs are candidates for removal in a later major, so each warning is upgrade debt for the next jump. Clear them while the context is fresh and then make those ids errors so they do not creep back.

  • If the upgraded app compiles without warnings, its behaviour has not changed.
  • ASPDEPR warnings mean the API is already removed and will fail at run time.
  • An 8-to-10 upgrade only needs the .NET 10 breaking-change list.
  • In .NET 10 cookie authentication still redirects every API request to the login page.
  • ASP.NET Core 10 can no longer produce an OpenAPI 3.0 document.

Assumes an upgrade from ASP.NET Core 8 to 10.0.x; every change listed is from the 9.0 or 10.0 breaking-change pages, and none is a .NET 11 preview behaviour.