I\'m developing an ASP.NET Web Api 2.2 with C#, .NET Framework 4.5.1.
After updating my Web.Api to Ninject 3.2.0 I get this error:
Error activating M
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: