错误:此模块需要Ninject.Web.WebAPI扩展名

时间:2016-07-01 18:51:26

标签: asp.net-mvc-5 ninject

我正在使用Ninject.Web.WebApi.OwinHost v3.2.4,我第一次点击页面时出现此错误。然后它从那时开始工作:

  

此模块需要Ninject.Web.WebAPI扩展名

堆栈跟踪是:

  

[InvalidOperationException:此模块需要Ninject.Web.WebAPI扩展名]      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(任务任务)+92      System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+58      Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext()+ 187      System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+92      System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+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

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

当您在不扫描Ninject模块的DLL的情况下创建内核时会发生这种情况,例如:

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

解决此问题的方法是手动加载Ninject.Web.WebApi.OwinHost需要的模块

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