Missing DependencyResolver in System.Web.Http 5.2.2

Our project uses asp.Net Web Api and part of our requirements to help users view data through Excel, we wanted to introduce OData Feed.

So, I installed the oData package:

<package id="Microsoft.AspNet.WebApi.OData" version="5.3.0" targetFramework="net45" /> 

Thus, the following packages were updated:

 - <package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net45" /> - <package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net45" /> + <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" /> + <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" /> - <package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" /> + <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" /> 

I modified my WebApiConfig a bit to add OData routes (but I think it doesn't matter, the reason why I don't give the code). The re-creation was repeated several times, so I decided to restart Visual Studio, as stated in several blog posts.

Then everything builds fine, and I run the debugger in the project. I get the following exception:

 An exception of type 'System.IO.FileLoadException' occurred in Ninject.Web.Common.dll but was not handled in user code Additional information: Could not load file or assembly 'System.Web.Http, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 

Then I will look at the Ninject configuration class to see the following line:

 GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); 

Shows "DependencyResolver" in red (The Resharper) and says that he cannot solve it. Looking at the Object Browser, I really can no longer find it.

So basically I upgraded Microsoft.AspNet.WebApi from 5.2.0 to 5.2.2 and lost DependencyResolver and Ninject compatibility.

Do you know a way around this?

+6
source share
1 answer

Ok, it seems I found a solution.

This is not incompatibility between ninject and 5.2.2 aspnet

The problem is that the oData installation updated some AspNet packages to 5.2.2, but forgot some others. When I receive all Microsoft.AspNet.WebApi * packages prior to version 5.2.2, the problem disappears.

I hope this helps other people anyway ...

+5
source

Source: https://habr.com/ru/post/975518/


All Articles