运行时编译错误来自Microsoft.AspNet.WebApi.HelpPage版本4.0.30506

时间:2013-12-05 10:34:30

标签: asp.net asp.net-mvc razor

当我尝试使用版本4.0.30506(不幸的是我们现在绑定到此版本的ASP.NEt Web API)时,我收到以下错误.Microsoft.AspNet.WebApi.HelpPage nuget包。我使用的是Windows 7和.NET 4.5。

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Source Error:


Line 11: 
Line 12:     // Group APIs by controller
Line 13:     ILookup<string, ApiDescription> apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor.ControllerName);
Line 14: }
Line 15: 

enter image description here

据我所知,我有所有正确的参考资料。我已经尝试过寻找一个System.Runtime程序集,但我在我的系统上找不到它。我已将使用语句添加到Index.cshtml的顶部,但没有任何影响。

@using System
@using System.Runtime

有关导致此错误的原因的任何建议?

3 个答案:

答案 0 :(得分:28)

检查你的web.config:

<compilation debug="true" targetFramework="4.5">
    <assemblies>
        <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </assemblies>
</compilation>

答案 1 :(得分:4)

在我的情况下,当我从Bin 目录中删除System.Collections.Immutable.dll时,此错误消失了。这个DLL来自NuGet包,仅适用于Win8平台,我正在使用Win7。所以它也可能对你有帮助..

答案 2 :(得分:2)

我在更新MVC 5,.NET 4.5.1项目中的所有Nuget包之后遇到了这个错误,并且感谢Dmitry Lyalin's post发现了与已成为可移植类库的更新的Nuget包有关的问题。

对于那些喜欢挖掘的人,我通过以下方式找出了罪魁祸首:

  1. 卸载项目unloading a VS project
  2. 修改项目
    editing a project
  3. 搜索“portable”found an unexpected portable library
  4. 找到Humanizer之后,我将其改回了PCL之前版本1.37.7,重新测试了页面,发现一切都恢复了。
  5. 知道罪魁祸首,在我的案例中,有两种选择:

    1. 将Humanizer Nuget置于版本1.x.y,以便不通过packages.config中的 allowedVersions 属性在v2中使用新的PCL库:
      <package id="Humanizer " version="1.37.7" allowedVersions="[1,2)" />
    2. 执行giammin在答案中建议的内容,并在web.config中的system.web下添加System.Runtime程序集:
      <system.web><compilation ...><assemblies><add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /></assemblies></compilation></system.web>