2

I recovered the following class from a CIL to C# converter (.Net reflector). Unfortunately, VS2010 won't compile it. Any idea how I can make it work?

using System;
using System.IO;
using System.Reflection;
internal class <Module>
{
    static <Module>()
    {
        IPLRes.ExeDirectory = new FileInfo(Assembly.GetExecutingAssembly>>().Location).DirectoryName;
        AppDomain expr_1E = AppDomain.CurrentDomain;
        expr_1E.AssemblyResolve += new ResolveEventHandler(expr_1E.AssemblyNotFound);
        IPLRes.LogDirectory = IPLRes.ExeDirectory + "\\log";
        IPLMsg.Log("Loader", "Application starting...");
    }
    public static Assembly AssemblyNotFound(object A_0, ResolveEventArgs A_1)
    {
        string text = A_1.Name;
        text = text.Remove(text.IndexOf(","));
        text = IPLRes.ExeDirectory + "\\bin35\\" + text + ".dll";
        return Assembly.LoadFile(text);
    }
    [STAThread]
    public static void IPLMain(string[] A_0)
    {
        if (A_0.Length >= 1)
        {
            IPLRes.BatchMode = A_0[0].Contains("batch");
        }
        if (!IPLRes.BatchMode)
        {
            IPLRes.ShowSplash("ipl_splash.png");
        }
        string[] array = new string[]
        {
            "-X:FullFrames", 
            "-X:Python30", 
            "-c", 
            IPLRes.GetString("ipl_entrypoint35.py")
        };
        IPLMsg.Log("Loader", "Starting main interpreter");
        IPLRes.MainInterpreter = new IronPythonHost();
        if (IPLRes.MainInterpreter.Run(array) != 0)
        {
            array = new string[]
            {
                "-c", 
                IPLRes.GetString("ipl_crash.py")
            };
            IPLMsg.Log("Loader", "Starting crash handler interpreter");
            IPLRes.CrashInterpreter = new IronPythonHost();
            IPLRes.CrashInterpreter.Run(array);
        }
        IPLMsg.Log("Loader", "Application shutting down.");
        IPLMsg.DumpLogFile();
    }
}
Bayo Alen
  • 341
  • 1
  • 6
  • 13
  • It means the compiler balks when it tries to compile the illegally-named class ``. Look at SLaks's answer to see what's actually going on here. – dlev Aug 22 '11 at 20:28
  • Consider adding the specific compiler error message -- even if the problem(s) can be seen without it, it adds background and reference. –  Aug 22 '11 at 20:36

1 Answers1

7

That's a module initializer, which C# does not support.

You can put it in the Main() instead.
You will need to move the rest of Main() to a separate method so that it can be JITted after adding the AssemblyResolve handler.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • [Module initializers in C#](http://stackoverflow.com/questions/1915506/module-initializers-in-c-sharp/17379410#17379410) – Sen Jacob Dec 13 '16 at 10:14