I have an MVC project targeting asp.net 4.7. And i have created a class library which targets .Net standard 2.0
If i reference the class library from my MVC Project i get the following exception on application startup.
System.MissingMethodException: 'Method not found:
Message "Method not found: 'System.Collections.ObjectModel.Collection`1 System.Web.Http.HttpConfiguration.get_MessageHandlers()'."
At
GlobalConfiguration.Configure(WebApiConfig.Register);
If i remove the reference everything is back to normal. Any ideas that may be wrong with that?
You need to add this binding redirect to 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>
如果您的mvc项目以.net 4.6.1为目标,则可以使用.net标准2.0类库。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.