0
votes

I'm using Ninject.Web.WebApi.OwinHost v3.2.4 and I get this error the first time you hit a page. Then it works from then on:

This module requires Ninject.Web.WebAPI extension

The stacktrace is:

[InvalidOperationException: This module requires Ninject.Web.WebAPI extension] Ninject.Web.WebApi.OwinHost.OwinWebApiModule.VerifyRequiredModulesAreLoaded() +202 Ninject.Modules.NinjectModule.OnVerifyRequiredModules() +10 Ninject.KernelBase.Load(IEnumerable``1 m) +419 Ninject.Web.Common.OwinHost.OwinBootstrapper.CreateKernel() +30 Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) +16 Ninject.Web.Common.OwinHost.d__1.MoveNext() +189 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +187 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__2.MoveNext() +185 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +64 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +380 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

How do I fix this?

1

1 Answers

3
votes

This occurs when you create your kernel without scanning the DLLs for Ninject modules, for example:

var kernel = new StandardKernel(new NinjectSettings
{
     LoadExtensions = false
});

The way to fix this is to manually load the modules that Ninject.Web.WebApi.OwinHost needs

kernel.Load(typeof(Ninject.Web.WebApi.WebApiModule).Assembly);