Start Debugging

native-aot

23 posts · Page 1 of 3

What is [ModuleInitializer] in C# and when should a library use it?

[ModuleInitializer] makes the C# compiler emit a <Module> static constructor that calls your method once per assembly. When it runs is looser than most people think: on the JIT it can fire before a branch that never executes, under Native AOT it runs eagerly at startup or not at all. Why CA2255 warns libraries off it, the few cases where a library should still use it, and measured behaviour on .NET 10.

Framework-dependent vs self-contained vs Native AOT for a .NET 11 container image

Framework-dependent on a chiseled aspnet image is the right default for an ASP.NET Core service on .NET 11, because the runtime layer is shared across services and a runtime CVE is fixed by a base image bump. Self-contained trimmed and Native AOT buy a 2x to 5x smaller image and a much faster cold start, and cost you that. Real published sizes, the layer-sharing math, and the .NET 11 base image inference bug that breaks the AOT path.
Next