Fixing the "Sequence contains no elements" error when starting up an ASP.NET web application after updating Ninject NuGet packages in the application

Posted: (EET/GMT+2)

 

If you have updated NuGet packages in your ASP.NET web application, and suddenly during application load you get an exception with the message "Sequence contains no elements", then there might be duplicate Ninject dependency injection initializations.

When you update Ninject NuGet packages, the package install automatically re-creates the file NinjectWebCommon.cs in the App_Start folder. If you initialize Ninject elsewhere, the duplicate initializations cause your application to fail at startup.

To fix the error, simply delete the extra file from your App_Start folder, and all should be fine.

Hope this helps!