4

I have added the NuGet package: Ninject.Web.WebApi.WebHost to my ASP.NET Web API project, however, once I add all of my DI bindings, I get the following error message:

Error activating HttpConfiguration More than one matching bindings are available. Matching bindings:
1) binding from HttpConfiguration to method
2) binding from HttpConfiguration to method
Activation path: 1) Request for HttpConfiguration
Suggestions: 1) Ensure that you have defined a binding for HttpConfiguration only once.

Ninject Error

These are the NuGet packages that are added along with Ninject.Web.WebAPI.WebHost:

  1. Ninject v. 3.2.2
  2. Ninject.Web.Common v. 3.2.3
  3. Ninject.Web.Common.WebHost v. 3.2.3
  4. Ninject.Web.WebApi v. 3.2.4
  5. Ninject.Web.WebApi.WebHost v. 3.2.4

I have no idea how to resolve this since I was able to get this to work on previous projects, but this project does not seem to be working for whatever reason.

I also encounter this error message frequently with all of these versions of the assemblies:

Make sure that the controller has a parameterless public constructor

Sometimes I am able to build the project correctly with older versions of the Ninject assemblies, but I frequently get the error message:

Sequence contains no elements.

The only way I have discovered to resolve this error is to delete the bin directory and re-build, but I don't understand why I constantly have to delete the bin directory to get Ninject to work properly each time.

Please advise as to how to get Ninject to work properly with Web API v.2.2

  • Did you ever figure this out. In my ninject at one point I saw two instances of HttpConfiguration. – tofutim Oct 24 '16 at 21:24

1 Answers1

0

I found the solution to this over here.

In short, the solution is to get all Ninject packages to the same version. There was a shuffling around of the HttpConfiguration stuff and if you have different versions of different Ninject packages, it can exist in multiple places. Upgrading everything to the same version should resolve this.

Community
  • 1
  • 1
Belizzle
  • 1,295
  • 3
  • 13
  • 28