I was having all sorts of grief with the WebApi2 and Ninject initialization after upgrading the Ninject packages (even uninstalling and deleting the old ones).
Specifically in your case I would remove these lines of code:
// Use the container and our NinjectDependencyResolver as
// application's resolver
var resolver = new NinjectDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
as they are probably the cause of the error (the NinjectWebCommon.cs and Ninject libraries deal with initializing the dependency resolver now).
For others out there who followed a similar upgrade path to me. What worked for me was the following:
-
Remove the old DependencyResolver initialization code (for me this was causing the specific error you mention as in earlier versions of Ninject/WebApi2, putting these lines in the WebApiConfig.cs Register() method was how you initialized the DependencyResolver…this no longer is the case):
var kernel = new StandardKernel(); config.DependencyResolver = new NinjectDependencyResolver(kernel); -
Install the Ninject.Web.WebApi.WebHost package. This installed the
NinjectWebCommon.cs file. For me, just having the Ninject.Web.WebApi and it’s
dependencies didn’t create this file.
My installed and working Ninject Packages for reference:
<package id="Ninject" version="3.2.2.0" targetFramework="net452" />
<package id="Ninject.Web.Common" version="3.2.3.0" targetFramework="net452" />
<package id="Ninject.Web.Common.WebHost" version="3.2.0.0" targetFramework="net452" />
<package id="Ninject.Web.WebApi" version="3.2.3.0" targetFramework="net452" />
<package id="Ninject.Web.WebApi.WebHost" version="3.2.3.0" targetFramework="net452" />