Ninject MVC3 - 引导程序抛出"已初始化"例外 [英] Ninject MVC3 - bootstrapper throwing "Already Initialized" exception

查看:151
本文介绍了Ninject MVC3 - 引导程序抛出"已初始化"例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个空的Asp.Net MVC3项目,并使用的NuGet 安装包Ninject.MVC3

I've created an empty Asp.Net MVC3 project, and used nuget install-package Ninject.MVC3

如果没有做别的事情(没有服务注册,甚至没有一个控制器上创建的)我运行应用程序。

Without doing anything else (no services registered and not even a controller created) I run the application.

第22行的项目断裂处NinjectMVC3.cs但以下情况除外:

The Project breaks on line 22 in NinjectMVC3.cs with the following exception:

[出现InvalidOperationException:已初始化]      Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback)在C:\项目\ Ninject \ Maintenance2.2 \ ninject.web.mvc \ MVC3的\ src \ Ninject.Web.Mvc \ Bootstrapper.cs>:58      Mvc.App_Start.NinjectMVC3.Start()在C:\项目\活动\活动\ App_Start \ NinjectMVC3.cs:22

[InvalidOperationException: Already Initialized!] Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Maintenance2.2\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\Bootstrapper.cs> :58 Mvc.App_Start.NinjectMVC3.Start() in c:\Projects\Events\Events\App_Start\NinjectMVC3.cs:22

[TargetInvocationException:异常   已经抛出的目标   调用]
  System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo   方法,对象的目标,对象[]   参数,SignatureStruct和放大器; SIG,   MethodAttributes methodAttributes,   RuntimeType typeOwner)+ 0
  System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo   方法,对象的目标,对象[]   参数,签名的签名,   MethodAttributes methodAttributes,   RuntimeType typeOwner)+72
  System.Reflection.RuntimeMethodInfo.Invoke(对象   OBJ,的BindingFlags invokeAttr,活页夹   粘合剂,对象[]参数,   的CultureInfo文化,布尔   skipVisibilityChecks)335
  System.Reflection.RuntimeMethodInfo.Invoke(对象   OBJ,的BindingFlags invokeAttr,活页夹   粘合剂,对象[]参数,   CultureInfo的文化)+28
  System.Reflection.MethodBase.Invoke(对象   OBJ,对象[]参数)+19
  WebActivator.BaseActivati​​onMethodAttribute.InvokeMethod()   +199 WebActivator.Activati​​onManager.RunActivati​​onMethods()   +330 WebActivator.Activati​​onManager.Run preStartMethods()   +27 WebActivator.Activati​​onManager.Run()   +39

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +335
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
WebActivator.BaseActivationMethodAttribute.InvokeMethod() +199 WebActivator.ActivationManager.RunActivationMethods() +330 WebActivator.ActivationManager.RunPreStartMethods() +27 WebActivator.ActivationManager.Run() +39

在NinjectMVC3.cs该生产线是:

The line in NinjectMVC3.cs is:

public static void Start() 
        {
            DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule));
            DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule));
            bootstrapper.Initialize(CreateKernel); // <- this one right here...
        }

这有什么怎么回事?我用Ninject的MVC3在其他项目中没有问题的。我也注意到,在开始()方法的第二个行不包含在以上(周)Ninject.MVC3的包,所以也许别的东西已经在最近的更新还坏了?

What is going on with this? I've used Ninject for MVC3 in other projects without problems at all. I do notice that the second line in the Start() method is not included in older (weeks) packages of Ninject.MVC3, so maybe something else has been broken in a recent update also?

请帮忙!

编辑从Remo的解决答案

这是从我的global.asax.cs

This is from my global.asax.cs

 public class MvcApplication : System.Web.HttpApplication
 {

在Global.asax是100%的标准以及。没有调整完成。

The global.asax is 100% standard aswell. No adjustments done.

修改 - 问题已经一去不复返了......

老实说,我不知道是什么原因造成这一点,但之后的Visual Studio,以及全面重启的一些重新启动,该项目是工作,因为它应该。我也不能重新创建新项目的问题。

I honestly have no idea what caused this, but after a few restarts of Visual Studio, and a full reboot, the project is working as it should. Neither can I recreate the problem in new projects.

抱歉浪费你的时间:)

推荐答案

问题消失了......

老实说,我不知道是什么原因造成这一点,但之后的Visual Studio,以及全面重启的一些重新启动,该项目是工作,因为它应该。我也不能重新创建新项目的问题。

I honestly have no idea what caused this, but after a few restarts of Visual Studio, and a full reboot, the project is working as it should. Neither can I recreate the problem in new projects.

抱歉浪费你的时间:)

更新

由于张贴这个答案了几个很好的答案已经显现。我更新这个答案,收集不同的方法在一个答案。希望这是确定为你们:

Since posting this answer a few good answers has appeared. I'm updating this answer to collect the different approaches in one answer. Hope that's ok for you guys:

DevilDog74 回答

终于我去gitub和克隆了   新的回购,下载最新的   Ninject.Web.Common和时尚Ninject2   发布版本,并做了​​局部释放   建立。   然后,我抛弃了的NuGet包和​​制作程序集引用新编译>组件Ninject,Ninject.Web.Common和Ninject.Web.Mvc我的项目开始>工作和控制器正在与他们的依赖是创建解决了。​​

finally i went to gitub and cloned a new repo, downloaded the latest Ninject.Web.Common and latest Ninject2 release builds and did a local release build. then I ditched the nuget packages and made assembly references to the newly compiled > assemblies "Ninject", "Ninject.Web.Common" and "Ninject.Web.Mvc" and my project started > working and controllers were being created with their dependencies being resolved.

杰夫 - 奇尔切奥的回答

我通过下载解决问题   从    https://github.com/ninject/ninject.web.mvc   代替使用的NuGet包。一世   没有后,我做任何事情   加入的参考文献。

I resolved the issue by downloading from https://github.com/ninject/ninject.web.mvc instead of using the nuget package. I didn't have to do anything after I added the references.

马库斯王回答

什么结束了工作对我来说是   除去Ninject MVC的NuGet包   彻底和公正的添加Ninject   和Ninject DLL的老式   方法。我觉得有可能是什么   错用自己的NuGet包。

What ended up working for me was to remove the Ninject MVC NuGet Package completely and just add the Ninject and Ninject dll's the old fashioned way. I think there may be something wrong with their NuGet package.

这篇关于Ninject MVC3 - 引导程序抛出&QUOT;已初始化&QUOT;例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆