title: Module initializers in C#
body: <p>Module initializers are a feature of the CLR that are not directly available in C# or VB.NET. They are global static methods named <code>.cctor</code> that are guaranteed to run before any other code (type initializers, static constructors) in an assembly are executed. I recently wanted to use this in a project and <a href="http://tech.einaregilsson.com/2009/12/16/module-initializers-in-csharp/" rel="noreferrer">hacked together my own solution (console program/msbuild task)</a> using Mono.Cecil, but I was wondering:</p>
  
  <ol>
  <li><p>Is there any way to trick the C# compiler into emitting module intializers? Any attributes (e.g. CompilerGenerated, SpecialName) or other trickery that could be used?</p></li>
  <li><p>Do the C# / VB.NET ever emit these initializers themselves for some purpose? From what I've seen they are used by managed C++ for some interop purposes, but I couldn't find any reference to them being used for other purposes. Any ideas?</p></li>
  </ol>