2010-03-24 28 views
1

我在一个XML文件中有一些代码,我在应用程序的运行时加载和编译它。CSharpCodeProvider'找不到元数据文件'使用Mono编译插件代码

这工作正常在Windows上,但在单声道我得到程序集引用错误。下面是检查代码中的问题:

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. 

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

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

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

回答

4

我不知道,如果你是在Linux或不运行,但你可能想尝试适当的资本DLL名称,因为Linux是大小写敏感的:

System.dll 
System.Xml.dll 
+0

完美!我不知道为什么我会认为这些程序集不区分大小写,但是这样做的确有用。谢谢。 – 2010-03-24 17:53:32