Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing DependencyResolver in System.Web.Http 5.2.2

Our project is using asp.Net Web Api and part of our requirements to exanble users to look at the 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" />

By doing so the following packages were upgraded:

-  <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 sligthly modified my WebApiConfig to add the OData routes (but I think this is irrelevant, reason why I don't give the code). Rebuild failed multiple times so I decided to restart Visual Studio as advised on multiple blog post.

Then all build fine and I launch the debugger on 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's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I then look at the Ninject configuration class to see that the following line:

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

Shows the "DependencyResolver" in red (That's Resharper) and says that it cannot resolve it. Looking at the Object Browser, I indeed cannot find it anymore.

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

Do you know a way to get around this?

like image 280
Georges Legros Avatar asked Sep 19 '14 07:09

Georges Legros


1 Answers

Ok seems like I found the solution.

It is not at all an incompatibility between the ninject and 5.2.2 of aspnet

Problem is that installing oData upgraded some AspNet packages to 5.2.2 but forgot some others. When I get all the Microsoft.AspNet.WebApi* packages to 5.2.2 the issue is going away.

I hope this will still help other people...

like image 125
Georges Legros Avatar answered Nov 19 '22 00:11

Georges Legros