' Sequence contains no elements' exception when initializing ninject
Asked Answered
C

6

22

I have a problem with Ninject which I have not seen before and don't know how to fix. I am using the MVC NuGet package for MVC 5.

In my NinjectWebCommon.cs, there is the following method:

    public static void Start() 
    {
        DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
        DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
        bootstrapper.Initialize(CreateKernel);
    }

However, it falls over when trying to execute the last line, complaining that the "sequence contains no elements". I was previously using Unity for DI but have changed to Ninject.

Any ideas?

Thanks in advance, M

Cartagena answered 16/7, 2014 at 9:13 Comment(3)
Not to worry, found the answer. I had two NinjectWebCommon.cs files on the go.Cartagena
I have only one NinjectWebCommon.cs file in the whole solution but still getting same issue.Georgia
#18993501 worked for meGeorgia
A
27

In my case, my project had two NinjectWebCommon.cs folders with the same/similar content. Dropping the folder has resolved the issue.

Armindaarming answered 7/3, 2017 at 17:0 Comment(1)
had multiple projects referencing ninject, after reinstalling library did not notice new NinjectWebCommon.cs. thanks a lot!Pedate
P
15

I faced this type of error while preparing a new solution by replacing File Name and other text in Entire solution.

Everything was perfect like buld the application.

But when i go to run the application it says me "Sequence contains no elements" error.

And finally i finally resolve that issue by using following.....

  1. open every project folder by right click on the project >> Then select "Open Folder in File Explorer

  2. Remove 'bin' and 'obj' folder

  3. Clean Entire project

  4. Build application

  5. and finally run the application.

Hopefully, it will work for you....

Thanks...

Parrnell answered 29/1, 2018 at 6:54 Comment(2)
I was trying every method on the internet sooo desperately, your answer too, and then, shazam! it all started to work again, Thank you so much.Derby
Five years later, this answer helped me AGAIN. I wish the question's owner would have accepted it. Right on. Thanks!Kratzer
S
14

For my two penneth and related to @Pavan's post. I started receiving the error after renaming an assembly. I had the old DLL lingering in the bin folder. Cleaning the solution didn't fix it. I had to go in and delete the contents of bin by hand.

Stella answered 15/3, 2017 at 22:36 Comment(2)
Thats an important answer and a more possible solution to the problem. Why would anybody normally have the NinjectWebCommon files in a single project:)Mordecai
This solved it for me. I refactored my project and changed the name of the assembly. When I published to Production, the production bin folder contained the dll with the old name, and hence forth I had 2 NinjectWebCommons wrecking my day.Temekatemerity
U
4

I think this is a dupe of this question: Ninject + MVC3 = InvalidOperationException: Sequence contains no elements

TL;DR - make sure you clear out all old dlls when you publish your site.

Unstriped answered 7/12, 2015 at 16:11 Comment(0)
N
0

An additional explanation detail to extend the helpful answer by @Greg_B:

A reference to another project in the solution that also uses Ninject. Removing this reference solves the problem.

Newscast answered 20/2, 2020 at 0:8 Comment(0)
S
0

I got this because I was trying to use version 5.0.0 of Castle.Core with version 3.3.5 of Ninject.Extensions.Interception.DynamicProxy, but that version of DynamicProxy only supports up to version 4.4.0 of Castle.Core

Downgrading to version 4.4.0 of Castle.Core fixed the problem for me

Slumber answered 12/12, 2023 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.