静态容器已经有一个与之关联的内核

时间:2014-12-25 23:07:14

标签: asp.net azure webforms ninject

部署到Azure时,我有与Ninject相关的错误:

The static container already has a kernel associated with it!

但它在当地运作良好。它之前一直在本地和Azure上工作,我不记得最近发生了什么变化(例如,我没有NuGet更新版本的Ninject)。我查了相关的帖子,但仍然无法解决我的问题。

以下是部署到Azure后的错误页面:

Server Error in '/' Application.

The static container already has a kernel associated with it!

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NotSupportedException: The static container already has a kernel associated with it!

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[NotSupportedException: The static container already has a kernel associated with it!]
   Ninject.Web.KernelContainer.set_Kernel(IKernel value) +68
   Ninject.Web.NinjectWebHttpApplicationPlugin.Start() +8
   Ninject.Web.Common.Bootstrapper.<Initialize>b__0(INinjectHttpApplicationPlugin c) +8
   Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) +130
   Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) +140
   AlamomiAdmin.App_Start.NinjectWebCommon.Start() in c:\a\src\AlamomiUniverse\AlamomiAdmin\App_Start\NinjectWebCommon.cs:26

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +155
   WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +57
   WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +350
   WebActivatorEx.ActivationManager.Run() +78

[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +547
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930568
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

1 个答案:

答案 0 :(得分:2)

我对此感到沮丧一个星期。今天我找到了解决方案。我想必须有两个重复的Ninject.dll / Ninject.Web.dll或Azure中Ninject的任何dll文件。因此,在部署之前,我必须删除Azure中的所有现有文件。我从Visual Studio部署。

所以这就是我所做的。在Visual Studio中,右键单击项目,然后选择“发布...”。在弹出窗口的“设置”下,选中“删除目标位置的其他文件”复选框。再次部署。

现在它成功了。