How the .NET compiler wires up ModuleInitializer methods, read from decompiled IL
A method marked with ModuleInitializer runs before any other code in an assembly, yet the runtime does not invoke the attribute directly. Decompiling the assembly reveals a static constructor on the reserved module pseudo-type that calls the initializer on the program's behalf. The initializer must be static, parameterless, void, non-generic, and accessible to the module, or the compiler rejects it. The article uses a simple example that sets a readiness flag to show the generated constructor and its IL metadata. It also explains how the free Glass.NET decompiler maps this synthesized code back to the original attributed methods using static analysis alone.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in