问题描述
我最近增加了两个Ninject和Ninject.Web.Mvc到现有的ASP.NET MVC 4 Web应用程序。在浏览网站,我收到下面的异常,看似随意:
I recently added both Ninject and Ninject.Web.Mvc to an existing ASP.NET MVC 4 web application. When browsing the site, I receive the following exception, seemingly at random:
[出现InvalidOperationException:错误加载Ninject组件ICACHE无
这样的组件已注册在内核中的组件
容器。
建议:1)如果你已经创建了一个自定义子类
KernelBase,确保您有正确
实施AddComponents()方法。 2)确保你没有通过一个呼叫中删除从容器组件
移除所有()。 3)确保您有不小心创造了超过
一个谷粒。 ] Ninject.Components.ComponentContainer.Get(类型
成分)的
C:\\项目\\ Ninject \\ ninject的\\ src \\ Ninject \\组件\\ ComponentContainer.cs:160
Ninject.Components.ComponentContainer.Get()的
C:\\项目\\ Ninject \\ ninject的\\ src \\ Ninject \\组件\\ ComponentContainer.cs:116
Ninject.Web.Common<> C_的 DisplayClass2.b 的_1(内核的iKernel)的
C:\\项目\\ Ninject \\ Ninject.Web.Common的\\ src \\ Ninject.Web.Common \\ OnePerRequestHttpModule.cs:74
Ninject.GlobalKernelRegistration.MapKernels(Action`1动作)在
C:\\项目\\ Ninject \\ ninject的\\ src \\ Ninject \\ GlobalKernelRegistration.cs:75
Ninject.Web.Common.OnePerRequestHttpModule.DeactivateInstancesForCurrentHtt prequest()
在
C:\\项目\\ Ninject \\ Ninject.Web.Common的\\ src \\ Ninject.Web.Common \\ OnePerRequestHttpModule.cs:74
Ninject.Web.Common.OnePerRequestHttpModule.b__0(对象o,
EventArgs的五)
C:\\项目\\ Ninject \\ Ninject.Web.Common的\\ src \\ Ninject.Web.Common \\ OnePerRequestHttpModule.cs:56
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+136 System.Web.HttpApplication.ExecuteStep(IExecutionStep一步,布尔和放大器; completedSynchronously)+69
Suggestions: 1) If you have created a custom subclass for KernelBase, ensure that you have properly implemented the AddComponents() method. 2) Ensure that you have not removed the component from the container via a call to RemoveAll(). 3) Ensure you have not accidentally created more than one kernel. ] Ninject.Components.ComponentContainer.Get(Type component) in c:\Projects\Ninject\ninject\src\Ninject\Components\ComponentContainer.cs:160 Ninject.Components.ComponentContainer.Get() in c:\Projects\Ninject\ninject\src\Ninject\Components\ComponentContainer.cs:116 Ninject.Web.Common.<>c_DisplayClass2.b_1(IKernel kernel) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\OnePerRequestHttpModule.cs:74 Ninject.GlobalKernelRegistration.MapKernels(Action`1 action) in c:\Projects\Ninject\ninject\src\Ninject\GlobalKernelRegistration.cs:75 Ninject.Web.Common.OnePerRequestHttpModule.DeactivateInstancesForCurrentHttpRequest() in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\OnePerRequestHttpModule.cs:74 Ninject.Web.Common.OnePerRequestHttpModule.b__0(Object o, EventArgs e) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\OnePerRequestHttpModule.cs:56 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
在我收到上述异常,只需刷新或点击回似乎导致该网站开始恢复正常运作。站点的没有一个区域似乎使其发生比另一处的任何更
Once I recieve the exception above, simply refreshing or clicking back seems to cause the site to begin functioning normally again. No one area of the site seems to cause it to occur any more than another.
问题颇为相似,这里提出这样的问题:Ninject +错误加载Ninject组件ICACHE。然而,在问题似乎通过与扩展本身的错误造成的,是一岁多了,看起来已经解决了。
The issue is quite similar to the question asked here: Ninject + "Error loading Ninject component ICache". However, the issue in that question seems to be caused by a bug with the extension itself, is over a year old, and looks to have been resolved.
这发生没有任何修改的 NinjectWebCommon.cs 文件,任何责任。 (没有模块加载,没有绑定添加)。对我来说,得到它停止的唯一方法是排除 NinjectWebCommon.cs 从项目,共
This occurs without any modification to the NinjectWebCommon.cs file, whatsoever. (No modules loaded, no bindings added.) The only way for me to get it to stop is to exclude NinjectWebCommon.cs from the project, altogether.
我不知道还有什么其他的信息,包括,因为我做的比安装的NuGet包小等。也许值得注意的是,这个项目是否包含对利用Ninject DI为其他程序集的引用。
I'm not sure what other information to include, as I've done little other than install the Nuget packages. Perhaps worth noting is that this project does include references to other assemblies that utilize Ninject for DI.
我环顾四周,颇有几分我对在为什么这会发生损失。任何建议将不胜AP preciated。
I've looked around quite a bit and am at a loss for why this would occur. Any suggestions would be greatly appreciated.
推荐答案
显然,有涉及您的应用程序(MVC +利布斯)多个内核。创建和应用程序的运行时期间处理内核实例是东西应该避免的。我强烈建议让尽可能少的内核是在应用程序启动创建改变设计。并随后建立无(包括所有库)。
Obviously there are multiple Kernels involved in your application (MVC + Libs). Creating and disposing kernel instances during runtime of the application is something that should be avoided. I strongly suggest to change your design so that as few kernels are created at application start. And none is created later (including all libs).
话虽如此,我没有看到在code这个问题怎么能与Ninject的最新版本发生任何关系。这可能是值得验证的应用程序和所有的图书馆都在Ninject的最新版本。
Having said that, I don't see any way in the code how this problem can happen with the latest version of Ninject. It may be worth verifying that the Application and ALL the libraries are on the latest version of Ninject.
这篇关于随机发生的Ninject例外:&QUOT;错误加载Ninject组件ICACHE&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!