Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error loading Ninject component ICache

I am using ninject in an asp.net web api project and have started receiving this intermittent ninject error:

"Error loading Ninject component ICache No such component has been registered in the kernel's component container."

I'm using:

  • Ninject 3.0.1.10
  • Ninject.MVC3 3.0.0.6
  • Ninject.Web.Common 3.0.0.7

They are all brought into my project with NuGet I load my Modules in IocConfig.RegisterIoc and have made no other changes or tweaks.

It may be unrelated but the problem started occurring at around the same time as I started injecting IKernel into one of my constructors. I didn't set up a binding for this having read about the "special resolver".

I have read through a number of similar questions on here:

Ninject + "Error loading Ninject component ICache"

Ninject and ChildKernel in MVC3 project: "Error loading Ninject component ICache"

Randomly-Occurring Ninject Exception: "Error loading Ninject component ICache"

Although in each of these cases the OP has the same error as me the solution is not appropriate - I am not creating child kernels and I'm not using the bugged version of ninject.

like image 641
Twisted Avatar asked Feb 07 '13 17:02

Twisted


1 Answers

Found the solution and thought I would share.

The problem was that I was Using Ninject.MVC3 which seems to be wrong package for Web-API.

Instead I need to use Ninject.Web.WebApi-RC package as described by this post:

http://www.eyecatch.no/blog/2012/06/using-ninject-with-webapi-rc/

Steps I followed for a fix are

  • Uninstalled Ninject.MVC3 and Ninject.Web.Common
  • delete all of the ninject files from the App_Start folder.
  • install Ninject.Web.Common and Ninject.Web.WebApi-RC from nuget
  • Load my modules in NinjectWebCommon.RegisterServices()
like image 97
Twisted Avatar answered Sep 23 '22 14:09

Twisted