Web api help page error CS0012: Type "System.Collections.Generic.Dictionary'2错误

时间:2023-03-08 16:13:52
Web api help page error CS0012: Type "System.Collections.Generic.Dictionary'2错误

1、在asp.net Boilerplate项目中,Abp.0.12.0.2,.net framework4.5.2。下载后添加了webApi的helpPage功能,调试出现错误。

dubug : at Areas\HelpPage\Views\Help\DisplayTemplatesHelpPageApiModel.cshtml Samples error:
D:\ project \MyWeb\MyWeb.Web\Areas\HelpPage\Views\Help\DisplayTemplates\Samples.cshtml (6): error CS0012: Type "System.Collections.Generic.Dictionary'2 <T0,T1>" defined in the Assembly that is not referenced. You must add the assemblies "System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" reference.

解决方法:在 Web.config, node <system.web> <assemblies>, adding
<add assembly="System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

解决:http://www.lyalin.com/2014/04/25/the-type-system-object-is-defined-in-an-assembly-that-is-not-reference-mvc-pcl-issue/

2、还是1的项目,debug时候正常,但发布到iis时候出现错误:

编译错误

说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。

编译器错误消息: CS0012: 类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用。

解决方法:在web.config中,node <system.web> <assemblies>, adding

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

效果:

<system.web>
<!--<trust level="Full" />-->
<globalization culture="auto" uiCulture="auto"/>
<compilation debug="true" targetFramework="4.5.2">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add assembly="System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation> <httpRuntime/>
<customErrors mode="Off"/>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>