' Sequence contains no elements' exception when initializing ninject

非 Y 不嫁゛ 提交于 2019-12-10 12:39:57

问题


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


回答1:


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




回答2:


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.




回答3:


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...




回答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.



来源:https://stackoverflow.com/questions/24776799/sequence-contains-no-elements-exception-when-initializing-ninject

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!