Skills migrate-dotnet8-to-dotnet9
git clone https://github.com/dotnet/skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/dotnet/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/dotnet-upgrade/skills/migrate-dotnet8-to-dotnet9" ~/.claude/skills/dotnet-skills-migrate-dotnet8-to-dotnet9 && rm -rf "$T"
plugins/dotnet-upgrade/skills/migrate-dotnet8-to-dotnet9/SKILL.md.NET 8 → .NET 9 Migration
Migrate a .NET 8 project or solution to .NET 9, systematically resolving all breaking changes. The outcome is a project targeting
net9.0 that builds cleanly, passes tests, and accounts for every behavioral, source-incompatible, and binary-incompatible change introduced in the .NET 9 release.
When to Use
- Upgrading
fromTargetFramework
tonet8.0net9.0 - Resolving build errors or new warnings after updating the .NET 9 SDK
- Adapting to behavioral changes in .NET 9 runtime, ASP.NET Core 9, or EF Core 9
- Replacing
usage (now always throws at runtime)BinaryFormatter - Updating CI/CD pipelines, Dockerfiles, or deployment scripts for .NET 9
When Not to Use
- The project already targets
and builds cleanly — migration is done. If the goal is to reachnet9.0
, use thenet10.0
skill as the next step.migrate-dotnet9-to-dotnet10 - Upgrading from .NET 7 or earlier — address the prior version breaking changes first
- Migrating from .NET Framework — that is a separate, larger effort
- Greenfield projects that start on .NET 9 (no migration needed)
Inputs
| Input | Required | Description |
|---|---|---|
| Project or solution path | Yes | The , , or entry point to migrate |
| Build command | No | How to build (e.g., , a repo build script). Auto-detect if not provided |
| Test command | No | How to run tests (e.g., ). Auto-detect if not provided |
| Project type hints | No | Whether the project uses ASP.NET Core, EF Core, WinForms, WPF, containers, etc. Auto-detect from PackageReferences and SDK attributes if not provided |
Workflow
Answer directly from the loaded reference documents. Do not search the filesystem or fetch web pages for breaking change information — the references contain the authoritative details. Focus on identifying which breaking changes apply and providing concrete fixes.
Commit strategy: Commit at each logical boundary — after updating the TFM (Step 2), after resolving build errors (Step 3), after addressing behavioral changes (Step 4), and after updating infrastructure (Step 5). This keeps each commit focused and reviewable.
Step 1: Assess the project
- Identify how the project is built and tested. Look for build scripts,
/.sln
files, or individual.slnx
files..csproj - Run
to confirm the .NET 9 SDK is installed. If it is not, stop and inform the user.dotnet --version - Determine which technology areas the project uses by examining:
- SDK attribute:
→ ASP.NET Core;Microsoft.NET.Sdk.Web
withMicrosoft.NET.Sdk.WindowsDesktop
or<UseWPF>
→ WPF/WinForms<UseWindowsForms> - PackageReferences:
→ EF Core;Microsoft.EntityFrameworkCore.*
→ HttpClientFactoryMicrosoft.Extensions.Http - Dockerfile presence → Container changes relevant
- P/Invoke or native interop usage → Interop changes relevant
usage → Serialization migration neededBinaryFormatter
usage → Serialization changes relevantSystem.Text.Json- X509Certificate constructors → Cryptography changes relevant
- SDK attribute:
- Record which reference documents are relevant (see the reference loading table in Step 3).
- Do a clean build (
or deletedotnet build --no-incremental
/bin
) on the currentobj
target to establish a clean baseline. Record any pre-existing warnings.net8.0
Step 2: Update the Target Framework
-
In each
(or.csproj
if centralized), change:Directory.Build.props<TargetFramework>net8.0</TargetFramework>to:
<TargetFramework>net9.0</TargetFramework>For multi-targeted projects, add
tonet9.0
or replace<TargetFrameworks>
.net8.0 -
Update all
,Microsoft.Extensions.*
,Microsoft.AspNetCore.*
, and other Microsoft package references to their 9.0.x versions. If using Central Package Management (Microsoft.EntityFrameworkCore.*
), update versions there.Directory.Packages.props -
Run
. Watch for:dotnet restore- Version requirements: .NET 9 SDK requires Visual Studio 17.12+ to target
(17.11 fornet9.0
and earlier).net8.0 - New warnings for .NET Standard 1.x and .NET 7 targets — consider updating or removing outdated target frameworks.
- Version requirements: .NET 9 SDK requires Visual Studio 17.12+ to target
-
Run a clean build. Collect all errors and new warnings. These will be addressed in Step 3.
Step 3: Resolve build errors and source-incompatible changes
Work through compilation errors and new warnings systematically. Load the appropriate reference documents based on the project type:
| If the project uses… | Load reference |
|---|---|
| Any .NET 9 project | |
| Any .NET 9 project | |
| Any .NET 9 project | |
| ASP.NET Core | |
| Entity Framework Core | |
| Cryptography APIs | |
| System.Text.Json, HttpClient, networking | |
| Windows Forms or WPF | |
| Docker containers, native interop | |
| Runtime configuration, deployment | |
Common source-incompatible changes to check for:
-
span overload resolution — Newparams
overloads onparams ReadOnlySpan<T>
,String.Join
,String.Concat
,Path.Combine
, and many more now bind preferentially. Code calling these methods insideTask.WhenAll
lambdas will fail (CS8640/CS9226). SeeExpression
.references/core-libraries-dotnet8to9.md -
ambiguous overload — TheStringValues
feature creates ambiguity withparams Span<T>
implicit operators on methods likeStringValues
,String.Concat
,String.Join
. Fix by explicitly casting arguments. SeePath.Combine
.references/core-libraries-dotnet8to9.md -
New obsoletion warnings (SYSLIB0054–SYSLIB0057):
: ReplaceSYSLIB0054
/Thread.VolatileRead
withVolatileWrite
/Volatile.ReadVolatile.Write
: ReplaceSYSLIB0057
/X509Certificate2
binary/file constructors withX509Certificate
methodsX509CertificateLoader- Also
(ARM AdvSimd signed overloads) andSYSLIB0055
(Assembly.LoadFrom with hash algorithm) — seeSYSLIB0056references/core-libraries-dotnet8to9.md
-
C# 13
on record structs —InlineArray
attribute on[InlineArray]
types is now disallowed (CS9259). Change to a regularrecord struct
. Seestruct
.references/csharp-compiler-dotnet8to9.md -
C# 13 iterator safe context — Iterators now introduce a safe context in C# 13. Local functions inside iterators that used unsafe code inherited from an outer
class will now error. Addunsafe
modifier to the local function. Seeunsafe
.references/csharp-compiler-dotnet8to9.md -
C# 13 collection expression overload resolution — Empty collection expressions (
) no longer use span vs non-span to tiebreak overloads. Exact element type is now preferred. See[]
.references/csharp-compiler-dotnet8to9.md -
removed — Code compiled against .NET 9 previews that passesString.Trim(params ReadOnlySpan<char>)
toReadOnlySpan<char>
/Trim
/TrimStart
must rebuild; the overload was removed in GA. SeeTrimEnd
.references/core-libraries-dotnet8to9.md -
always throws — If the project usesBinaryFormatter
, stop and inform the user — this is a major decision. SeeBinaryFormatter
.references/serialization-networking-dotnet8to9.md -
is nullable — The property is nowHttpListenerRequest.UserAgent
. Add null checks. Seestring?
.references/serialization-networking-dotnet8to9.md -
Windows Forms nullability annotation changes — Some WinForms API parameters changed from nullable to non-nullable. Update call sites. See
.references/winforms-wpf-dotnet8to9.md -
Windows Forms security analyzers (WFO1000) — New analyzers produce errors for properties without explicit serialization configuration. See
.references/winforms-wpf-dotnet8to9.md
Build again after each batch of fixes. Repeat until the build is clean.
Step 4: Address behavioral changes
Behavioral changes do not cause build errors but may change runtime behavior. Review each applicable item and determine whether the previous behavior was relied upon.
High-impact behavioral changes (check first):
-
Floating-point to integer conversions are now saturating — Conversions from
/float
to integer types now saturate instead of wrapping on x86/x64. Seedouble
.references/deployment-runtime-dotnet8to9.md -
EF Core: Pending model changes exception —
/Migrate()
now throws if the model has pending changes. Search forMigrateAsync()
,DateTime.Now
, orDateTime.UtcNow
in anyGuid.NewGuid()
call — these must be replaced with fixed constants (e.g.,HasData
). Seenew DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc)
.references/efcore-dotnet8to9.md -
EF Core: Explicit transaction exception —
inside a user transaction now throws. SeeMigrate()
.references/efcore-dotnet8to9.md -
HttpClientFactory uses
by default — Code that casts the primary handler toSocketsHttpHandler
will getHttpClientHandler
. SeeInvalidCastException
.references/serialization-networking-dotnet8to9.md -
HttpClientFactory header redaction by default — All header values in
-level logs are now redacted. SeeTrace
.references/serialization-networking-dotnet8to9.md -
Environment variables take precedence over runtimeconfig.json — Runtime configuration settings from environment variables now override
. Seeruntimeconfig.json
.references/deployment-runtime-dotnet8to9.md -
ASP.NET Core
/ValidateOnBuild
in development —ValidateScopes
now enables DI validation in development by default. SeeHostBuilder
.references/aspnet-core-dotnet8to9.md
Other behavioral changes to review (may cause runtime exceptions ⚠️ or subtle behavioral differences):
- ⚠️
no longer injects non-keyed service fallback — throwsFromKeyedServicesAttributeInvalidOperationException - ⚠️ Container images no longer install zlib — apps depending on system zlib will fail
- ⚠️ Intel CET is now enabled by default — non-CET-compatible native libraries may cause process termination
now has a maximum length ofBigInteger
bits(2^31) - 1
deserialization of JSONJsonDocument
now returns non-nullnull
withJsonDocument
instead of C#JsonValueKind.Nullnull
metadata reader now unescapes metadata property namesSystem.Text.Json
names/comments now respect the UTF-8 flagZipArchiveEntry
initial callback is now asynchronousIncrementingPollingCounter
prepends rootDir to filesInMemoryDirectoryInfo
returns a different typeRuntimeHelpers.GetSubArray
raisesPictureBox
instead ofHttpRequestExceptionWebException
uses a different default rendererStatusStrip
support is opt-inIMsoComponent
up-refs the handleSafeEvpPKeyHandle.DuplicateHandle
metrics reportHttpClient
unconditionallyserver.port- URI query strings redacted in HttpClient EventSource events and IHttpClientFactory logs
is incompatible with Hot Reload for old frameworksdotnet watch- WPF
returnsGetXmlNamespaceMaps
instead ofHashtableString
Step 5: Update infrastructure
-
Dockerfiles: Update base images. Note that .NET 9 container images no longer install zlib. If your app depends on zlib, add
to your Dockerfile.RUN apt-get update && apt-get install -y zlib1g# Before FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build FROM mcr.microsoft.com/dotnet/aspnet:8.0 # After FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build FROM mcr.microsoft.com/dotnet/aspnet:9.0 -
CI/CD pipelines: Update SDK version references. If using
, update:global.json{ "sdk": { "version": "9.0.100", "rollForward": "latestFeature" } }Review the
policy — if set torollForward
or"disable"
, the SDK may not resolve correctly after upgrading."latestPatch"
(recommended) allows the SDK to roll forward to the latest 9.0.x feature band."latestFeature" -
Visual Studio version: .NET 9 SDK requires VS 17.12+ to target
. VS 17.11 can only targetnet9.0
and earlier.net8.0 -
Terminal Logger:
now uses Terminal Logger by default in interactive terminals. CI scripts that parse MSBuild console output may needdotnet build
or--tl:off
.MSBUILDTERMINALLOGGER=off -
output: Output format has changed. Update any scripts that parse workload command output.dotnet workload -
.NET Monitor images: Tags simplified to version-only (affects container orchestration referencing specific tags).
Step 6: Verify
- Run a full clean build:
dotnet build --no-incremental - Run all tests:
dotnet test - If the application is containerized, build and test the container image
- Smoke-test the application, paying special attention to:
- BinaryFormatter usage (will throw at runtime)
- Floating-point to integer conversion behavior
- EF Core migration application
- HttpClientFactory handler casting and logging
- DI validation in development environment
- Runtime configuration settings (environment variable precedence)
- Review the diff and ensure no unintended behavioral changes were introduced
Reference Documents
The
references/ folder contains detailed breaking change information organized by technology area. Load only the references relevant to the project being migrated:
| Reference file | When to load |
|---|---|
| Always (C# 13 compiler breaking changes — InlineArray on records, iterator safe context, collection expression overloads) |
| Always (applies to all .NET 9 projects) |
| Always (SDK and build tooling changes) |
| Project uses ASP.NET Core |
| Project uses Entity Framework Core |
| Project uses System.Security.Cryptography or X.509 certificates |
| Project uses BinaryFormatter, System.Text.Json, HttpClient, or networking APIs |
| Project uses Windows Forms or WPF |
| Project uses Docker containers or native interop (P/Invoke) |
| Project uses runtime configuration, deployment, or has floating-point to integer conversions |