Skip to content


Repository files navigation


Chat on Gitter NuGet Status

Adds a module initializer to an assembly.

This is an add-in for Fody

It is expected that all developers using Fody either become a Patron on OpenCollective, or have a Tidelift Subscription. See Licensing/Patron FAQ for more information.


See also Fody usage.

NuGet installation

Install the ModuleInit.Fody NuGet package and update the Fody NuGet package:

PM> Install-Package Fody
PM> Install-Package ModuleInit.Fody

The Install-Package Fody is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.

Add to FodyWeavers.xml

Add <ModuleInit/> to FodyWeavers.xml


What it does

Based on Einar Egilsson's suggestion using cecil to create module initializers []

Finds a class, in the target assembly, named 'ModuleInitializer' with the following form.

public static class ModuleInitializer
    public static void Initialize()
        //Init code

Injects the following code into the module initializer of the target assembly. This code will be called when the assembly is loaded into memory

static <Module>()


Icon courtesy of The Noun Project