2013-09-24 7 views
7

Ich benutze MVC 4 und Ninject 3 mit NinjectWebCommon im Ordner App_Start."Server Fehler in '/' Anwendung. Sequenz enthält keine Elemente" nach Refactoring Namespace

Und mein Global.asax.cs ist MvcApplication: Httpapplication

Ich erhalte den Fehler unten, weil die Ninject Start zweimal ist - warum?

Server Error in '/' Application. 

Sequence contains no elements 

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.InvalidOperationException: Sequence contains no elements 

Source Error: 


Line 50:    kernelInstance = createKernelCallback(); 
Line 51: 
Line 52:    kernelInstance.Components.GetAll<INinjectHttpApplicationPlugin>().Map(c => c.Start()); 
Line 53:    kernelInstance.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); 
Line 54:    kernelInstance.Inject(this); 

Source File: c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs Line: 52 

Stack Trace: 


[InvalidOperationException: Sequence contains no elements] 
    System.Linq.Enumerable.Single(IEnumerable`1 source) +315 
    Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() in c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectMvcHttpApplicationPlugin.cs:53 
    Ninject.Web.Common.Bootstrapper.<Initialize>b__0(INinjectHttpApplicationPlugin c) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:52 
    Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:32 
    Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:52 
    Company.App.App_Start.NinjectWebCommon.Start() in c:\Development\Company\trunk\src\App\App_Start\NinjectWebCommon.cs:29 

[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) +108 
    System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19 
    WebActivator.BaseActivationMethodAttribute.InvokeMethod() +236 
    WebActivator.ActivationManager.RunActivationMethods() +534 
    WebActivator.ActivationManager.RunPreStartMethods() +41 
    WebActivator.ActivationManager.Run() +64 

[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.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) +550 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90 
    System.Web.Compilation.BuildManager.ExecutePreAppStart() +135 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516 

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.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) +9874568 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044 

Antwort

34

Dies wurde verursacht, wenn ich die Namespaces und den binären Namen refaktorierte.

Dies bedeutete, dass eine alte Kopie der DLL mit dem alten Namen immer noch im bin-Ordner war.

Das bedeutete, dass beide DLLs beim Start aktiviert wurden.

A Sauber hat es nicht entfernt, also löschte ich manuell und das Problem ging weg.

+2

Vielen Dank dafür. Allerdings musste ich nicht nur die Bin-Ordner entfernen, sondern musste auch eine Datenträgerbereinigung durchführen, um das Webprojekt zu erstellen. Ich nehme an, dass es alte Dateien im temporären Speicher verwendete. – contactmatt

+1

Vielen Dank Mann .... es hat mir den Kopf abgebissen .... Vielen Dank ... – Shaz

+0

Das gleiche für mich, ich hatte das gleiche Problem und keine andere Lösung funktioniert. – brimble2010

0

Ich bin auf dieses Problem gestoßen und habe ein paar Stunden damit verbracht, verschiedene Empfehlungen im Internet auszuprobieren. Die Sache, die es am Ende behob, war, nach zirkulären Referenzen über Namespaces in meinem Projekt zu suchen. Werfen Sie einen Blick auf Ihre .csproj-Dateien und überprüfen Sie, ob alle Referenzen korrekt sind

0

Für mich hatte ich versehentlich Ninject in ein Nicht-Web-Projekt installiert, das Entfernen von meinem Datenprojekt löste das Problem für mich.