问题描述
当部署到Azure中我有这个错误涉及到Ninject:
静态容器已有与之关联的内核!
但它在当地的正常工作。它一直致力于本地和Azure的面前,我不记得什么样的变化最近发生的(如,我没的NuGet Ninject的更新版本)。我查了一下相关的帖子,但还是解决不了我的问题。
下面是当部署到Azure的后错误页面:
在'/'应用程序的服务器错误。静态容器已有与之关联的内核!说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。异常详细信息:System.NotSupportedException:静态容器已有与之关联的内核!源错误:当前Web请求的执行过程中生成了未处理的异常。有关异常的来源和位置信息可以使用异常堆栈跟踪下面确定。堆栈跟踪:
[NotSupportedException异常:静态容器已有与之关联的内核!]
Ninject.Web.KernelContainer.set_Kernel(的iKernel值)+68
Ninject.Web.NinjectWebHttpApplicationPlugin.Start()+8
Ninject.Web.Common.Bootstrapper<&初始化GT; b__0(INinjectHttpApplicationPlugin C)+8
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1系列,Action`1动作)+ 130
Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback)+140
AlamomiAdmin.App_Start.NinjectWebCommon.Start()在C:\\ A \\ SRC \\ AlamomiUniverse \\ AlamomiAdmin \\ App_Start \\ NinjectWebCommon.cs:26[TargetInvocationException:异常已被调用的目标引发异常。]
System.RuntimeMethodHandle.InvokeMethod(对象的目标,对象[]参数,签名的签名,布尔构造器)+ 0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(obj对象,对象[]参数,对象[]参数)+192
System.Reflection.RuntimeMethodInfo.Invoke(obj对象,的BindingFlags invokeAttr,粘结剂粘合,对象[]参数,CultureInfo的文化)+155
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod()+57
WebActivatorEx.ActivationManager.RunActivationMethods(布尔designerMode)+350
WebActivatorEx.ActivationManager.Run()+78[出现InvalidOperationException:在pre-应用程序启动的类型WebActivatorEx.ActivationManager运行投用以下错误消息的异常初始化方法:异常被抛出由目标调用的..]
System.Web.Compilation.BuildManager.Invoke preStartInitMethodsCore(ICollection`1方法,Func`1 setHostingEnvironmentCultures)547
System.Web.Compilation.BuildManager.Invoke preStartInitMethods(ICollection`1方法)+132
System.Web.Compilation.BuildManager.Call preStartInitMethods(字符串preStartInitListPath,布尔和放大器; isRefAssemblyLoaded)+102
System.Web.Compilation.BuildManager.Execute preAppStart()+153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager的AppManager,IApplicationHost APPHOST,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParameters hostingParameters,PolicyLevel policyLevel,异常appDomainCreationException)521[HttpException(0x80004005的):在pre-应用程序启动的类型WebActivatorEx.ActivationManager运行投用以下错误消息的异常初始化方法:异常被抛出由目标调用的..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext的背景下)9930568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext的背景下)+101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR,HttpContext的背景下)+254
我已经一个星期受挫这一点。今天,我找到了解决办法。我想必须有两个在Azure中复制Ninject.dll / Ninject.Web.dll或任何dll文件从Ninject。所以,我在部署之前,我必须删除Azure的所有现有文件。我从Visual Studio部署。
因此,这里是我做过什么。在Visual Studio中,右键单击项目,并选择发布...。在弹出窗口中,在设置,勾选名为目的地删除其他文件复选框。重新部署。
现在它成功。
I have this error related to Ninject when deploy to Azure:
The static container already has a kernel associated with it!
But it works fine in local. And it has always been working on both local and Azure before, and I don't remember what changes happened recently (e.g., I didn't NuGet a newer version of Ninject). I checked related posts but still cannot solve my problem.
Here is the error page when after deployed to 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
I have been frustrated by this for a week. Today I found the solution. I figured there must be two duplicate Ninject.dll/Ninject.Web.dll or whatever dll files from Ninject in Azure. So I must remove all existing files in Azure before I deploy. I deploy from Visual Studio.
So here is what I did. In Visual Studio, right click project, and select "Publish...". In the popup window, under "Settings", check the checkbox named "Remove additional files at destination". Deploy again.
Now it succeeds.
这篇关于静态容器已有与之关联的内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!