Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when referencing .Net Standard 2.0 library from Asp.Net 4.7 project

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?

like image 581
Anestis Kivranoglou Avatar asked Dec 12 '25 07:12

Anestis Kivranoglou


1 Answers

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>
like image 148
Hrvoje Hudo Avatar answered Dec 14 '25 20:12

Hrvoje Hudo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!