尝试使用 .netstandard 2 程序集时出现 Web Api 2 运行时错误 [英] Web Api 2 run-time error when trying to use .netstandard 2 assembly

查看:33
本文介绍了尝试使用 .netstandard 2 程序集时出现 Web Api 2 运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个引用 .net 4.6.1 的 Asp.net WebApi 2 站点.至目前为止该站点引用了一个 PCL 程序集(可移植类库),以与 UWP 兼容.Xamarin,没有问题.现在,我正尝试按照建议将该 PCL 更改为 NetStandard2.0 程序集,但在站点启动时收到错误消息.

I have an Asp.net WebApi 2 site referencing .net 4.6.1. Up till now the site was referencing a PCL assembly (portable class library), for compatibility with UWP & Xamarin, without issues. Now I am trying to change that PCL to a NetStandard2.0 assembly, as recommended, but am receiving an error at site start up.

错误如下 -

未找到方法:'System.Collections.ObjectModel.Collection`1System.Web.Http.HttpConfiguration.get_MessageHandlers()'.

Method not found: 'System.Collections.ObjectModel.Collection`1 System.Web.Http.HttpConfiguration.get_MessageHandlers()'.

有什么想法吗?谢谢

推荐答案

我得到了同样的结果.我将此添加到我的 web.config 并且它起作用了.<代码><从属程序集><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>

I was getting the same thing. I added this to my web.config and it worked. <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>

哦,绑定重定向的乐趣.

Oh the joys of Binding Redirects.

这篇关于尝试使用 .netstandard 2 程序集时出现 Web Api 2 运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆