' Sequence contains no elements' exception when initializing ninject

serlingpa picture serlingpa · Jul 16, 2014 · Viewed 8.7k times · Source

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

Answer

Pavan Nayakanti picture Pavan Nayakanti · Mar 7, 2017

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