Skip to the content.

Experimental. The longer story, with everything that went wrong along the way, is in notes/findings.md.

No runtime

A zero app is compiled by the official .NET Native AOT compiler, but against a tiny replacement for the base class library. That replacement defines just enough types for C# to compile and for the AOT compiler to produce an exe. With no runtime library to link, the exe contains your code and almost nothing else.

What you have:

What you don’t have:

Why no reflection is fine: generics resolved at compile time

protobuf-net builds serializers at run time, from attributes it reads by reflection. Here the source generator does that work at compile time, and the library’s entry points are generic over interfaces with static abstract members:

public static bool TrySerialize<T>(in T value, Span<byte> destination, out int bytesWritten)
    where T : IProtoMessage<T>, allows ref struct

Every call binds to the contract’s own static methods for that T, so there is no virtual dispatch, no casting and no lookup. allows ref struct lets a contract or view that holds spans be the T.

One library binary, two worlds

The minimal base library is an assembly called System.Runtime, with the same identity as the real one: name, public key token and a version no higher than any host’s. It exposes a strict subset of the real System.Runtime, with the same signatures.

System.Runtime is what ordinary .NET libraries reference anyway, a contract that the real runtime forwards to its core library. So ProtoBuf.Zero.dll, compiled against the subset:

It is the same file in both, and the repository’s build checks that the two produce identical bytes. It also means zero libraries need no shared “micro-BCL” of their own to agree on: the shared surface is whichever part of System.Runtime they use. A library that wants to stay usable from zero apps must use only that subset, and must allocate and throw nothing.

The cross-checks

Every build of the repository: