【问题标题】:Compilation error at runtime from Microsoft.AspNet.WebApi.HelpPage version 4.0.30506来自 Microsoft.AspNet.WebApi.HelpPage 版本 4.0.30506 的运行时编译错误
【发布时间】:2013-12-05 10:34:29
【问题描述】:

当我尝试使用 Microsoft.AspNet.WebApi.HelpPage nuget 包的 4.0.30506 版(不幸的是,我们目前与此版本的 ASP.NEt Web API 相关联)时出现以下错误。我正在使用 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: 

据我所见,我拥有所有正确的参考资料。我已尝试按照它的建议寻找 System.Runtime 程序集,但在我的系统上找不到它。我在 Index.cshtml 的顶部添加了 using 语句,但没有任何影响。

@using System
@using System.Runtime

关于导致此错误的任何建议?

【问题讨论】:

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


【解决方案1】:

检查您的 web.config:

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

【讨论】:

  • 第一个 sn-p 添加到我的 Index.cshtml 时出现解析器错误。这是有效的 Razor 语法吗?它适用于第二个 sn-p 但没有第一个。
  • @jamesj 一​​个错字 # 而不是 % 但我不是剃须刀大师...我不确定...
  • @jamesj 乐于助人! :D 比我删除第一个 sn-p
  • 我在我的视图中对枚举使用了扩展方法,这帮助我修复了我的视图编译问题 - 谢谢! :)
  • 是的,它可以工作,但我想知道为什么配置文件没有自动更新,它只是
【解决方案2】:

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

【讨论】:

  • 我已经添加然后删除了 System.Collections.Immutable.dll 并开始收到错误。从 bin 中删除后,错误消失了。
【解决方案3】:

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

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

  1. 卸载项目
  2. 编辑项目
  3. 搜索“便携”
  4. 找到 Humanizer 后,我将其改回 PCL 之前的 1.37.7 版本,重新测试页面,发现一切正常。

在我的情况下,知道罪魁祸首 Humanizer,有两个选择:

  1. 在版本 1.x.y 中限制 Humanizer Nuget,以免通过 packages.config 中的 allowedVersions 属性使用 v2 中的新 PCL 库:
    &lt;package id="Humanizer " version="1.37.7" allowedVersions="[1,2)" /&gt;
  2. 按照 giammin 在他的回答中的建议,在 web.config 中的 system.web 下添加 System.Runtime 程序集:
    &lt;system.web&gt;&lt;compilation ...&gt;&lt;assemblies&gt;&lt;add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /&gt;&lt;/assemblies&gt;&lt;/compilation&gt;&lt;/system.web&gt;

【讨论】:

  • 感谢您发现这一点。
猜你喜欢
  • 2015-12-28
  • 1970-01-01
  • 2012-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多