Programming

.NET 11 Is Out. Union Types Got the Applause, but unsafe Is What Changed.

.NET 11 shipped on November 10, 2026, and C# 15 finally has union types, the feature people have asked for since pattern matching arrived.

Code on a computer screen
Photo by Rob Wingate / Unsplash

A method that looks up a product has two honest outcomes: here it is, or it doesn't exist. C# has never had an honest return type for that. You return null and hope the caller checks. You throw an exception for something that isn't exceptional. You invent a base class that exists only so two unrelated types can share a return slot. Each one works, and none of them lets the compiler tell the caller, "there are exactly two cases here and you handled one."

.NET 11 shipped on November 10, 2026, and C# 15 closes that gap with union types. That's the headline and it deserves to be. But the same SDK carries a preview that changes what the unsafe keyword means, and that matters more if you review code for a living.

What's New in .NET 11 and C# 15

First, the support terms, from Microsoft's announcement:

Release Type Support
.NET 11 Standard Term Support (STS) Two years
.NET 10 Long Term Support (LTS) Still supported

Microsoft says STS and LTS releases "have the same quality and servicing policies; the difference is the length of support." If you're on .NET 10 and happy, nothing forces a move.

C# 15 is the default language version for projects targeting net11.0. Its feature list, from the language documentation:

Feature What it gives you Preview flag needed?
Union types A value that is one of a fixed set of types No
Closed hierarchies A class that can only be derived from in its own assembly No
Collection expression arguments with(...) to pass capacity or a comparer No
Extension indexers Indexers declared in an extension block No
Labeled break and continue Jump out of nested loops by name No
Static interface members on older runtimes Non-virtual static helpers without runtime support No
Memory safety New rules for unsafe Yes

Union Types

A union declares that a value is one of several case types. This is the example from Microsoft's release announcement:

ProductLookup result = new Product(42, "Mechanical keyboard");

string message = result switch
{
    Product product => $"Found {product.Name}",
    ProductNotFound missing => $"No product with ID {missing.Id}",
};

Console.WriteLine(message);

public sealed record Product(int Id, string Name);
public sealed record ProductNotFound(int Id);
public union ProductLookup(Product, ProductNotFound);

Two things happen here that didn't before. new Product(...) converts to ProductLookup implicitly, so there's no wrapper to construct. And the switch has no default arm, because the compiler knows the full list of cases and checks that you covered them.

That second part is the point. Add a third case to the union next year, say ProductDiscontinued, and every switch that doesn't handle it stops compiling cleanly. The "I forgot the new state" bug moves from production to the build.

This matters for more than tidiness. A lot of authorization and state-machine bugs are a missed case: the code handled Approved and Denied and fell through on Pending. A type that lists every state, checked by the compiler, removes that class of mistake from code that uses it.

Closed Hierarchies

Unions cover unrelated types. Closed hierarchies do the same job for an inheritance tree. From the documentation:

public closed record class GateState;
public record class Closed : GateState;
public record class Open(float Percent) : GateState;

A closed class can only be derived from inside its own assembly, so the compiler knows every direct descendant and can check a switch against them:

string Describe(GateState state) => state switch
{
    Closed => "closed",
    Open(var percent) => $"{percent}% open",
    // No warning: every direct descendant of 'GateState' is handled.
};

There's a catch the documentation is upfront about, and it's the kind that bites later. Derivation "isn't transitive." A non-closed descendant of a closed class can still be extended from other assemblies. If Open isn't itself marked closed, someone else can subclass it, and your exhaustive switch still matches their type as an Open. To carry the guarantee down the tree, mark the intermediate classes closed too.

We recommend reading C# 14 Is Actually Good And I'm Not Happy About It to continue reading our selection of content. C# 15's extension indexers build directly on the extension blocks that piece covers, and it's the context for how the language got here.

C# 14 Is Actually Good And I'm Not Happy About It C# 14's most significant new features explained — what changed, why it matters, and why the language that used to mean enterprise bloat is now genuinely good. SudoSecurity · Santhdium

The Memory Safety Preview

C# is a memory-safe language with an escape hatch. Mark a block unsafe and you can use pointers. For more than twenty years the rule has been simple: if a pointer type appears, you need unsafe.

The problem with that rule is that it flags the wrong thing. Declaring an int* hurts nobody. Reading through it is what corrupts memory. The documentation states the new goal directly: "to tie the unsafe context to the operations that actually access unmanaged memory, rather than to the existence of pointer types."

Microsoft calls this the start of "a multirelease effort to redefine memory safety in the language." The first step looks backwards at first glance, because it removes the unsafe requirement from several operations:

  • Declaring a pointer type and taking an address with &
  • The fixed statement
  • Converting a stackalloc expression to a pointer
  • sizeof on any unmanaged type

So with the preview language version, this compiles without an unsafe context:

int number = 42;
int* pointer = &number;

int[] numbers = [10, 20, 30];
fixed (int* first = numbers)
{
    // Dereferencing the pointer still requires an unsafe context.
}

What still requires unsafe is the list that matters: pointer indirection (*p), member access (p->member), element access (p[i]), and calling a function pointer.

The effect is a smaller, more accurate audit surface. Today a reviewer searching for unsafe finds blocks that only declare or pass pointers alongside the ones that dereference them. Under the new rules, the keyword marks the lines that can do damage.

The second half is stricter. With the updated rules on, unsafe on a member marks it as "requires-unsafe." In the documentation's words, "the audit obligation flows to the caller, who must use the member from an unsafe context." Today you can wrap dangerous code in a method with a safe-looking signature and callers never know. Under the new model, the danger shows up at every call site. A new safe keyword covers the other direction, for extern members you've reviewed and want to vouch for.

If that sounds familiar, it should. It's close to how Rust treats an unsafe fn: the caller takes on the obligation, and the keyword marks where a human has to check what the compiler can't.

It's a preview with two switches. LangVersion set to preview gets you the syntax and the pointer relaxations. The stricter caller rules need the updated-memory-safety-rules compiler feature as well. Don't ship on it. Do try it on a library with interop code, because the unsafe you'll be asked to add is a map of where your real risk is.

We recommend reading Rust Is Memory Safe. Somebody Still Does the Knife Work. to continue reading our selection of content. It shows the model C# is moving toward, by reading the unsafe code that sits underneath Rust's safe standard library.

Rust Is Memory Safe. Somebody Still Does the Knife Work. Vec::push writes through a raw pointer, get_unchecked skips the check, mem::forget is safe. Read from the Rust standard library. SudoSecurity · Santhdium

The Runtime: Async Moves Out of the Compiler

Since C# 5, async methods have been compiled into state-machine classes. .NET 11 moves that job into the runtime. Microsoft's runtime notes call it "a significant step toward replacing compiler-generated async state machines with runtime-managed suspension and resumption," with "cleaner stack traces, better debuggability, and lower overhead."

It's opt-in for your code, with one project property:

<PropertyGroup>
  <Features>runtime-async=on</Features>
</PropertyGroup>

It no longer needs EnablePreviewFeatures, and the runtime libraries themselves are now compiled this way, which is a real vote of confidence. Microsoft is still asking for reports on throughput and library size, so measure before you flip it in production.

The Hardware Floor Went Up

This one can stop an app from starting. .NET 11 raises the minimum x86/x64 baseline from x86-64-v1 to x86-64-v2 on every operating system:

Before .NET 11
x86/x64 minimum x86-64-v1 x86-64-v2 (adds SSE4.2, POPCNT, and others)
ReadyToRun target, Windows and Linux x86-64-v2 x86-64-v3 (adds AVX2 and others)
Windows on Arm64 No LSE requirement Requires LSE
Linux on Arm64 armv8.0 No change to the minimum; Raspberry Pi still works

On hardware below the floor, the runtime refuses to run and prints "The current CPU is missing one or more of the baseline instruction sets." Microsoft says the last x86 chips without these instructions went out of vendor support around 2013. That's old for a laptop and not that old for an industrial PC or a hand-me-down homelab box. Check before you upgrade anything that runs on donated hardware.

Library and SDK Changes Worth Knowing

From the overview, the ones with a security or operations angle:

  • Zstandard is built in, in System.IO.Compression. ZIP entries now get CRC32 validation on read.
  • TLS gets handshake hardening and certificate-validation alerts on Linux.
  • Cryptography adds an X25519DiffieHellman class and AES Key Wrap. Composite ML-KEM and HPKE APIs are in, marked experimental.
  • Process APIs gain run-and-capture helpers and Process.Signal(PosixSignal).
  • Container publishing produces reproducible image digests through SOURCE_DATE_EPOCH. If you verify what you deploy, a build that hashes the same twice is what makes that possible.
  • The CLI now starts from a Native AOT entry point with the MSBuild server on by default, and its telemetry moved from Application Insights to OpenTelemetry.

What This Doesn't Cover

This covers the language, the runtime, and a slice of the libraries. It skips ASP.NET Core, .NET MAUI, EF Core, F#, and the AI tooling Microsoft's announcement spends a lot of time on.

I had no .NET 11 SDK in my test environment, so nothing here was compiled by me. Every code block is copied from Microsoft's documentation or announcement. The description of the memory safety preview is from the C# 15 documentation. It's a preview, the design is explicitly multi-release, and details can change before it's final.

The comparison to Rust is mine. Microsoft's documentation doesn't make it.

The Actual Point

Union types and closed hierarchies let you write down every state a value can be in and have the compiler hold you to it. That removes the missed-case bug from code that adopts them, and you can use both today without a preview flag.

The unsafe work is slower and matters more. C# is narrowing the keyword to the operations that can corrupt memory and pushing the obligation out to callers. For anyone who audits .NET code, that turns unsafe from a rough hint into a list of the lines worth reading. Turn the preview on in a branch, look at what it flags, and you'll have a head start on rules that are coming either way.

All code blocks above are reproduced from Microsoft's documentation and release announcement, not written or compiled by me: the union example is from Announcing .NET 11, the closed-hierarchy and pointer examples are from What's new in C# 15, and the project property is from What's new in the .NET 11 runtime. Support terms, hardware requirements, and library changes are from those pages and the .NET 11 overview, as of November 14, 2026.

$ tail -f /forums

Discussion

Comments live on the community forums — sign in there to reply.