This is supposedly the way to force a static constructor to run multiple times:
typeof(Foo).TypeInitializer.Invoke(null, null);
That does not work for me. See this dotnetfiddle, example which has this:
using System;
public static class Foo
{
static Foo()
{
Console.WriteLine("inside cctor");
}
public static void Run() { }
}
public class Program
{
public static void Main()
{
Foo.Run(); // runs cctor
typeof(Foo).TypeInitializer.Invoke(null, null); // does not run cctor
typeof(Foo).TypeInitializer.Invoke(null, null); // does not run cctor
typeof(Foo).TypeInitializer.Invoke(null, null); // does not run cctor
}
}
That prints "inside cctor" only once. I expected it to run multiple times.