Web Api 2 run-time error when trying to use .netstandard 2 assembly

时间秒杀一切 提交于 2019-12-22 18:43:23

问题


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.

The error is below -

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

Any ideas? Thanks


回答1:


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.



来源:https://stackoverflow.com/questions/45720729/web-api-2-run-time-error-when-trying-to-use-netstandard-2-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!