【问题标题】:Why does this disassembled code not compile in C#?为什么这个反汇编代码不能在 C# 中编译?
【发布时间】:2011-08-22 20:24:38
【问题描述】:

我从 CIL 到 C# 转换器(.Net 反射器)恢复了以下类。不幸的是,VS2010 不会编译它。知道如何让它发挥作用吗?

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();
    }
}

【问题讨论】:

  • 这意味着编译器在尝试编译非法命名的类&lt;Module&gt;时会失败。看看 SLaks 的回答,看看这里到底发生了什么。
  • 考虑添加特定的编译器错误消息——即使没有它可以看到问题,它也会添加背景和参考。

标签: c# module cil reflector


【解决方案1】:

这是一个模块初始化器,C# 不支持。

你可以把它放在 Main() 中。
您需要将 Main() 的其余部分移至单独的方法,以便在添加 AssemblyResolve 处理程序后对其进行 JIT。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-09-09
  • 2010-10-24
  • 2014-03-01
  • 2010-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-06
相关资源
最近更新 更多