【问题标题】:CSharpCodeProvider 'cannot find metadata file' Compiling Plugin Code With MonoCSharpCodeProvider '找不到元数据文件' 用 Mono 编译插件代码
【发布时间】:2011-12-15 13:20:51
【问题描述】:

我在一个 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 编译的代码中添加引用程序集的方式。其他两个程序集添加得很好,这并不奇怪,因为它们是编译器实际执行的代码,并且存在于可执行目录中。

任何线索我需要做些什么来解决这个问题?

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

【问题讨论】:

    标签: c# .net mono


    【解决方案1】:

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

    System.dll
    System.Xml.dll
    

    【讨论】:

    • 完美!我不知道为什么我会认为这些程序集不区分大小写,但这确实有效。谢谢。
    猜你喜欢
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    • 2017-04-20
    • 2021-07-06
    • 2022-10-20
    • 2015-08-21
    相关资源
    最近更新 更多