代码之家  ›  专栏  ›  技术社区  ›  Jason Champion

csharpcodeprovider“找不到元数据文件”正在使用mono编译插件代码

  •  1
  • Jason Champion  · 技术社区  · 15 年前

    我在XML文件中有一些代码,在应用程序运行时加载和编译。

    这在windows上工作得很好,但是在mono下我会得到程序集引用错误。下面是有问题的检查代码:

    public static bool CompileSpell(Spell spell)
    {
                CSharpCodeProvider prov = new CSharpCodeProvider();
                CompilerParameters cp = new CompilerParameters();
                cp.GenerateExecutable = true;
                cp.GenerateInMemory = true;
                cp.ReferencedAssemblies.Add("system.dll");
                cp.ReferencedAssemblies.Add("system.xml.dll");
                cp.ReferencedAssemblies.Add("BasternaeMud.dll");
                cp.ReferencedAssemblies.Add("ZoneData.dll");
    
                Log.Trace("Compiling spell '" + spell.Name + "'.");
    
                StringBuilder sb = new StringBuilder();
                int idx = spell.FileName.IndexOf('.');
                string file = spell.FileName;
                if (idx > 0)
                {
                    file = spell.FileName.Substring(0, idx);
                }
                int lines = GenerateWithMain(sb, spell.Code, "BasternaeMud");
    
                CompilerResults cr = prov.CompileAssemblyFromSource(cp,sb.ToString());
                ....
    

    我在编译器结果中得到的具体错误是:

    cannot find metadata file 'system.dll' at line 0 column 0.
    cannot find metadata file 'system.xml.dll' at line 0 column 0.
    

    mono显然不喜欢将引用的程序集添加到为system.xml和system.xml.dll编译的代码中的方式。另外两个程序集添加fine,这并不奇怪,因为它们是编译器实际执行的代码,并且存在于可执行目录中。

    你知道我需要做什么来解决这个问题吗?

    也许我可以把这些dll放到可执行目录中,但这感觉是个愚蠢的想法。

    1 回复  |  直到 13 年前
        1
  •  4
  •   mellamokb Dan    13 年前

    我不知道您是否在Linux上运行,但您可能需要尝试正确地将dll名称大写,因为Linux区分大小写:

    System.dll
    System.Xml.dll