asp.net-web-apininjectninject.web.mvc

Could not load type 'Ninject.Web.WebApi.IWebApiRequestScopeProvider' from assembly 'Ninject.Web.WebApi'


I've recently upgraded my solution to .net Framework 4.8 and updated a load of nuget packages and now I'm having problems getting my API project to launch.

I felt this smelled of bad binding redirect, but I've looked at this and they are as follows...

  <dependentAssembly>
    <assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.3.4.0" newVersion="3.3.4.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Ninject.Web.Common" publicKeyToken="c7192dc5380945e7" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.3.2.0" newVersion="3.3.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Ninject.Web.Common.OwinHost" publicKeyToken="c7192dc5380945e7" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Ninject.Web.WebApi" publicKeyToken="c7192dc5380945e7" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
  </dependentAssembly>

And here's the packages.config...

  <package id="Ninject" version="3.3.4" targetFramework="net48" />
  <package id="Ninject.Extensions.NamedScope" version="3.3.0" targetFramework="net48" />
  <package id="Ninject.Web.Common" version="3.3.2" targetFramework="net48" />
  <package id="Ninject.Web.Common.OwinHost" version="3.3.1" targetFramework="net48" />
  <package id="Ninject.Web.Common.WebHost" version="3.3.2" targetFramework="net48" />
  <package id="Ninject.Web.WebApi" version="3.3.1" targetFramework="net48" />
  <package id="Ninject.Web.WebApi.OwinHost" version="3.3.0" targetFramework="net48" />

There's no specific redirect here for Ninject.Web.WebApi.OwinHost so I'm thinking that may be the issue or maybe one of the other libraries, but they never had redirects before and I've tried...

Get-Package MyApp.Api | Add-Bindings

(excuse the syntax here - it may be wrong as from memory)

...to add relevant bindings that were missing.


Solution

  • This was caused by a versioning issue with Nuget packages (This is why I don't use Ninject by choice anymore...)

    I downgraded the WebApi package as follows...

    <package id="Ninject.Web.WebApi" version="3.3.0" targetFramework="net48" />
    

    So that it was in line with Ninject.Web.WebApi.OwinHost, cleaned, rebuilt and tried again and it all worked perfectly.

    I would suspect that the Ninject.Web.WebApi.OwinHost package hasn't been updated yet and isn't compatible.