Interview frequency: …
Short answer
It compiles code directly into a native executable without requiring a JIT compiler or installed .NET Runtime, reducing startup time and memory use but limiting Reflection.
Explanation
Native Ahead-Of-Time (AOT) removes unused code (Trimming) and compiles the entire application into a small, self-contained executable. It is valuable for Serverless functions and minimal containers, where startup can drop to tens of milliseconds and RAM use can be cut in half. Its main limitation is that dynamic code generation and Reflection incompatible with static analysis are not supported.
Code example
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>Common mistakes
- Trying to publish an application that relies on old libraries with heavy Reflection as Native AOT without replacing them with Source Generators.