正在获取运行时错误程序集';System.Runtime';在使用CSharpCodeProvider时

本文关键字:CSharpCodeProvider Runtime System 程序集 获取 运行时错误 | 更新日期: 2023-09-27 18:00:40

我收到关于缺少引用的运行时错误。

类型"System.Object"是在程序集中定义的,而不是引用。必须添加对程序集"System.Runtime,版本=4.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a'

我使用MVC应用程序,并在代码中使用了CSharpCodeProvider。

我没有得到任何编译错误,但得到compileResult的运行时错误,如上所述,为什么?

 CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);

我甚至在web.cofig中添加了assemblies标签,就像下面同样的错误一样。有什么线索吗?

  <assemblies>     
    <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />   
  </assemblies>

正在获取运行时错误程序集';System.Runtime';在使用CSharpCodeProvider时

ASP.NET MVC经常使用dynamic关键字。这可能是问题的根源,因为这需要Microsoft.CSharp程序集(您显然已经包含了它)和System.Runtime程序集(我认为缺少这个程序集。

在编译配置中添加System.Runtime程序集:

parameters.ReferencedAssemblies.Add("mscorlib.dll"); // guess you have this one already
parameters.ReferencedAssemblies.Add("System.Runtime.dll");
相关文章:
  • 没有找到相关文章