Start Debugging

Daily notes on .NET, C#, EF Core, MAUI, Blazor, and Flutter - for developers who ship.

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.
Page 1 of 110 Next ›