Skip to content

3.9 — .NET Standard

← Roadmap · Section: 3. .NET Runtime and Platform Prev: 3.8 The .NET CLI · Next: 3.10 Release cadence

Markers: — · Confidence: 🔴 · Last reviewed: —


TL;DR

.NET Standard is a list of APIs that several different .NET platforms all promised to provide. A library targeting it could run on .NET Framework, .NET Core, Xamarin and Mono without being rebuilt for each.

  • It is not a runtime. Nothing "runs on .NET Standard" — it is a contract, not a platform.
  • It solved a real problem in the split years, and the unification in .NET 5 made it mostly obsolete.
  • Today you only target it if you must support .NET Framework consumers.

Definitions

Term What it is What it means
.NET Standard a specification A list of APIs that multiple .NET platforms all agree to implement. Not a runtime.
netstandard2.0 a TFM The most useful version. The last one .NET Framework supports.
netstandard2.1 a TFM A later version .NET Framework never supported. Usually the wrong choice.
Implementation an actual platform .NET Framework, .NET Core, Mono, Xamarin — the things that provide the APIs.
Contract assembly a reference-only .dll Has the API shapes but no working code. What you compile against when targeting Standard.
PlatformNotSupportedException an exception type Thrown when an API exists in the contract but is not implemented on the platform you are running on.
Type forwarding a linking mechanism Lets a type declared in the contract resolve to the real one in the running platform.

The concept

The problem it was invented to solve

Rewind to around 2016. There were several separate .NET platforms, and they were genuinely different products:

  • .NET Framework — Windows
  • .NET Core — cross-platform servers
  • Xamarin — iOS and Android
  • Mono — Linux and Unity
  • UWP — Windows Store apps

If you wrote a library, which one did you build for? Building for all of them meant five builds, five test runs and five sets of quirks.

.NET Standard was the answer: an agreed list of APIs that all of them promised to provide. Target the list rather than any one platform, and your single library works on all of them.

A picture: a plug standard rather than a specific socket. You do not build one kettle for UK sockets, one for EU, one for US. You agree a shape, everyone supports it, and one kettle works everywhere.

Why it is mostly obsolete now

The reason is simple: the platforms merged.

.NET 5 unified .NET Core, Mono and Xamarin into one product (3.1). When there is only one platform, there is nothing to standardise between.

Microsoft's own guidance now is:

net10.0 for anything new. netstandard2.0 only if you must support .NET Framework.

.NET Standard is frozen at 2.1 and will never gain a new version. It exists purely for backwards compatibility.


How it works

The simple version — which version to pick

Version Supported by Use it?
netstandard2.0 .NET Framework 4.6.1+, .NET Core 2.0+, Mono, Xamarin ✅ The only one worth targeting, if you need Framework consumers
netstandard2.1 .NET Core 3.0+, Mono, Xamarin — not .NET Framework ❌ Almost never. See below.

netstandard2.1 is the trap. It looks like the newer, better option. But .NET Framework never supported it, which removes the entire reason to target Standard in the first place. If your consumers are all on modern .NET, target net10.0 directly and get the full API surface. So netstandard2.1 occupies a niche that barely exists.

The decision comes down to one question:

Do I need .NET Framework consumers?
├── Yes → netstandard2.0
└── No  → net10.0 (or whichever current version)

How it actually works — contracts and type forwarding

When you compile against netstandard2.0, you are not compiling against real code. You are compiling against a contract assembly — a .dll containing the API shapes with no implementations.

At runtime, on whichever platform you land, type forwarding redirects each type to the platform's real implementation. So System.String in the contract resolves to .NET Framework's String on Framework, and .NET 10's String on .NET 10.

That is why one build genuinely works everywhere: the contract is stable and each platform supplies the real thing.

⚠️ The compiles-but-throws problem

Because the contract lists APIs the majority of platforms support, some entries are not actually implemented everywhere. Those compile fine and throw at runtime:

// Compiles against netstandard2.0.
// Throws PlatformNotSupportedException on some platforms.
var key = new RSACryptoServiceProvider();

This is the practical weakness of the approach. The contract promises more than every implementation delivers, and you only discover the gap on the platform where it fails.

The mitigation is straightforward: test on every platform you claim to support. A library that says it targets netstandard2.0 and has only ever been run on .NET 10 has not really been verified.

The deeper detail — multi-targeting is usually better

If you need both Framework consumers and modern APIs, multi-targeting beats .NET Standard:

<TargetFrameworks>net10.0;netstandard2.0</TargetFrameworks>

This builds twice. The net10.0 build gets the full modern API surface — Span<T>, IAsyncEnumerable<T>, everything. The netstandard2.0 build gets the smaller shared set for Framework consumers. NuGet gives each consumer the right one automatically.

Compare with targeting netstandard2.0 alone, where everybody — including your modern .NET consumers — is limited to the 2015-era API surface.

Where the two builds differ, use conditional compilation (3.7):

public static bool Contains(string text, char value)
{
#if NETSTANDARD2_0
    return text.IndexOf(value) >= 0;              // no char overload back then
#else
    return text.Contains(value);                   // modern, faster
#endif
}

netstandard2.0 also misses a lot that you can partly recover with packages:

Missing from netstandard2.0 Polyfill package
Span<T>, Memory<T> System.Memory
IAsyncEnumerable<T> Microsoft.Bcl.AsyncInterfaces
System.Text.Json System.Text.Json
Nullable annotations Nullable (build-time only)

Those close much of the gap, at the cost of extra dependencies your consumers inherit.


Code

A library supporting both worlds properly:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net10.0;netstandard2.0</TargetFrameworks>
    <Nullable>enable</Nullable>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <!-- Only the old target needs these polyfills -->
  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
    <PackageReference Include="System.Text.Json" Version="8.0.5" />
    <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
    <PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
  </ItemGroup>

</Project>

Note LangVersion=latest. The C# language version is independent of the target framework, so you can use modern syntax like records and pattern matching even when targeting netstandard2.0 — as long as the feature does not need a runtime type that is missing. Records work; Span<T> does not without the polyfill.


Interview questions

Q: What is .NET Standard?

A specification listing APIs that several .NET platforms all agreed to implement. It is not a runtime — nothing runs on .NET Standard. It existed because around 2016 there were several separate .NET platforms, and a library author otherwise had to build separately for each. Targeting the standard meant one build that worked on .NET Framework, .NET Core, Xamarin and Mono alike.

Q: Is it still relevant?

Mostly not. It solved a fragmentation problem, and .NET 5 removed the fragmentation by unifying those platforms into one product. It is frozen at 2.1 and will never gain another version. The one remaining reason to target netstandard2.0 is if you publish a library that must still be consumable from .NET Framework, since that is the last version Framework supports. For anything else you target the current .NET directly and get the full API surface.

Q: Why would you target netstandard2.0 rather than netstandard2.1?

Because .NET Framework supports 2.0 and never supported 2.1. Supporting Framework consumers is essentially the only remaining reason to target Standard at all, so 2.1 removes the point of the exercise. If all your consumers are on modern .NET you should target net10.0 directly rather than 2.1, because you get the full API surface. That leaves 2.1 covering a niche that barely exists in practice.

Q: If you need to support both Framework and modern .NET, what would you do?

Multi-target rather than targeting .NET Standard alone. With <TargetFrameworks>net10.0;netstandard2.0</TargetFrameworks> the modern build gets the complete current API surface while the Standard build serves Framework consumers, and NuGet hands each consumer the right one. Targeting netstandard2.0 on its own would restrict everybody — including your modern consumers — to a 2015-era API surface. Where the two builds genuinely differ you bridge it with conditional compilation.


Traps ⚠️

  • "It's a runtime." It is a specification. Nothing executes on .NET Standard.
  • Targeting netstandard2.1 gets you the worst of both — no Framework support, and a smaller API surface than targeting modern .NET.
  • Some APIs compile but throw PlatformNotSupportedException. The contract promises more than every implementation delivers.
  • Targeting Standard alone limits your modern consumers too, not just the old ones.
  • It is frozen. No version after 2.1 will ever ship.
  • The C# language version is independent of the target. You can use modern syntax on netstandard2.0, provided the feature does not need a missing runtime type.
  • Polyfill packages become your consumers' dependencies too. Adding System.Memory puts it in everyone's dependency tree.


Sources