Back to JetBrains

C# Interceptors: Native AOT & Performance for Free | Stefan Pölz | .NET Day 2026

JetBrainsOctober 15, 202640m
In a Nutshell

C# interceptors let source generators replace specific method calls at compile time by emitting compatible methods with InterceptsLocation attributes, enabling Native AOT compatibility for Minimal APIs without code changes. The .NET team ships a Request Delegate Generator that intercepts MapGet/MapPost calls, moving reflection and dynamic IL generation from runtime to build time. This delivers Native AOT benefits—fast startup, no JIT overhead, smaller executables—while maintaining the original developer experience.

AI-Generated Notes

These notes were generated by AI and may contain inaccuracies.

Stefan Hertz presents on C# interceptors, Native AOT, and free performance. Interceptors were an experimental feature in .NET 8 and have been publicly available since .NET 9. This is not a feature of the C# language itself, but a feature of the compiler that integrates into systems using source code generators.

The session covers: introduction to interceptors, Native AOT technology, source code generators, and how these components link together so a source code generator can issue an interceptor that allows compilation of Native AOT in some scenarios.

Stefan identifies as a contributor to the JetBrains community, Microsoft MVP, and organizer of .NET meetups in Vienna. His focus is on how the compiler works from the inside, how to use it in certain scenarios, and how the .NET team implements features for best possible performance. This session continues from a session given 4 years ago at the "JetBrains .NET developer days" event where he discussed incremental source generators.

Interceptors in their current general availability (GA) version are difficult to explain, so the preview version introduced in .NET 8 is demonstrated instead. Warnings appear because this preview version is outdated and may be removed by the compiler at any time, possibly by the release of dotnet 11. The older version still works and illustrates what interceptors really do.

A simple console application demonstrates two methods: a static method and an instance method, both printing "ordinary method". These are called ordinary methods, while getters, setters, constructors, delegates, and local functions are different types of methods from Roslyn's perspective. The static method receives "Hello World" and the instance method receives "dotnet days online".

Sign in to read the full notes

Get access to AI-generated notes, topic timestamps, and more.