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 getting same error and uninstalled package Ninject.Web.WebApi.WebHost and error removed.
I uninstalled the package Ninject.Web.WebApi.WebHost and error is no more exists or occurred.
I have struggled with this in OWIN for a while and always ended up reverting to previous version. But nothing like checking the example application on their github.
First make sure you get rid of any manual Dependency Resolver you may be adding to the configuration, and then just do the following during your startup:
appBuilder.UseNinjectMiddleware(() => yourKernel); // or a function that returns your kernel
appBuilder.UseNinjectWebApi(yourHttConfiguration);
That should work fine.
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" />