Anestis Kivranoglou
Anestis Kivranoglou

Reputation: 8164

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?

Upvotes: 2

Views: 1205

Answers (2)

Hrvoje Hudo
Hrvoje Hudo

Reputation: 9024

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>

Upvotes: 8

Ken Tucker
Ken Tucker

Reputation: 4156

If your mvc project targets .net 4.6.1 you can use a .net standard 2.0 class library with it.

Upvotes: 0

Related Questions