Ninject + MVC3 = InvalidOperationException: Sequence contains no elements

asp.net-mvc-3, ninject

Solution

You might notice that after installing the `ninject.mvc3` NuGet there is an `App_Start` subfolder created inside your project containing an `NinjectMVC3.cs` file. Delete this folder and try again. So here are the steps I followed:

- Create a new ASP.NET MVC 3 project using the default template

- Bring up the Package Manager Console window (View -> Other Windows -> Package Manager Console)

- Type `install-package ninject.mvc3` on the command line

- Replace the default code in `Global.asax` with the code in your question

- Delete the `AppStart` subfolder created during the installation of the package

- Run the application

- Enjoy the beauty of the `/Home/Index` default page opened in your Google Chrome web browser :-)

Problem

I created a new MVC3 project, hit F5, saw the sample page. Then I used NuGet to get the Ninject.MVC extension. I modified my global.asax according to the Ninject documentation, How To Setup an MVC3 Application: ``` public class MvcApplication : NinjectHttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }); } protected override IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); return kernel; } protected override void OnApplicationStarted() { base.OnApplicationStarted(); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } } ``` Now when I run the app, I get the yellow screen of death with the following exception: InvalidOperationException - Sequence contains no elements. at System.Linq.Enumerable.Single(...) at Ninject.Web.Mvc.Bootstrapper.Initialize(...) line 67. And sure enough, line 67 of that file calls .Single(), thus throwing the exception. What am I doing wrong?

Original source