【问题标题】:Web Api 2 run-time error when trying to use .netstandard 2 assembly尝试使用 .netstandard 2 程序集时出现 Web Api 2 运行时错误
【发布时间】:2017-08-23 23:10:50
【问题描述】:
我有一个引用 .net 4.6.1 的 Asp.net WebApi 2 站点。至目前为止
该站点引用了 PCL 程序集(可移植类库),以便与 UWP 和 Xamarin 兼容,没有问题。现在我正在尝试按照建议将该 PCL 更改为 NetStandard2.0 程序集,但在站点启动时收到错误消息。
错误如下 -
找不到方法:
'System.Collections.ObjectModel.Collection`1
System.Web.Http.HttpConfiguration.get_MessageHandlers()'。
有什么想法吗?
谢谢
【问题讨论】:
标签:
c#
asp.net
asp.net-web-api
.net-standard
【解决方案1】:
我得到了同样的东西。我将此添加到我的 web.config 并且它有效。
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
哦,绑定重定向的乐趣。