ninject/Ninject.Web.Mvc

Sequence contains no elements - Bootstrapper

thomen opened this issue · 9 comments

System.Linq.Enumerable.Single(IEnumerable`1 source) +379
Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() in c:\Projects\Ninject\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\NinjectMvcHttpApplicationPlugin.cs:53

I cannot seem to get this up and running. I've followed the instructions to the letter..

nothing changed in global I'm using the App_Start folder

[assembly: WebActivator.PreApplicationStartMethod(typeof(EFWebApp.Web.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(EFWebApp.Web.App_Start.NinjectWebCommon), "Stop")]

namespace EFWebApp.Web.App_Start
{
using System;
using System.Web;

using Microsoft.Web.Infrastructure.DynamicModuleHelper;

using Ninject;
using Ninject.Web.Common;

public static class NinjectWebCommon
{
    private static readonly Bootstrapper bootstrapper = new Bootstrapper();

    /// <summary>
    /// Starts the application
    /// </summary>
    public static void Start()
    {
        DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
        DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
        bootstrapper.Initialize(CreateKernel);
    }

    /// <summary>
    /// Stops the application.
    /// </summary>
    public static void Stop()
    {
        bootstrapper.ShutDown();
    }

    /// <summary>
    /// Creates the kernel that will manage your application.
    /// </summary>
    /// <returns>The created kernel.</returns>
    private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
        kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

        RegisterServices(kernel);
        return kernel;
    }

    /// <summary>
    /// Load your modules or register your services here!
    /// </summary>
    /// <param name="kernel">The kernel.</param>
    private static void RegisterServices(IKernel kernel)
    {
        kernel.Load<EFWebNinjectModule>();
    }
}

}

This means that the DataAnnotationsModelValidatorProvider is removed by someother library or you use App_Start and derive from NinjectHttpApplication at the same time.

How do I find out / fix if DataAnnotationsModelValidatorProvider was removed?

If I remember correctly this can occur if you derive from
NinjectWebApplication in addition to using App_Start.

Have you verified that you don't derive from NinjectWebApplication?

2012/11/19 Saulo Vallory notifications@github.com

How do I find out / fix if DataAnnotationsModelValidatorProvider was
removed?


Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-10503709.

Yes. That's why I asked about the DataAnnotationsModelValidatorProvider removed thing :/

Couldn't solve the issue, so I uninstalled Ninject and started adding todo's where I'm hard coding the instantiation to deal with this later. Any help will be much appreciated!

Found the problem! I have tree projects in my solution (Domain, Infra and UI). I accidentally installed Ninject in two of them (infra and UI) which created two NinjectWebCommon classes. This was the cause of the issue. Once I removed the ninject package from infra, the problem was solved. :)

@svallory thank you for the update! This helped me

The easiest solution is to delete the NinjectWebCommon.cs class created under the App_Start directory and allow the MvcApplication inheriting from NinjectHttpApplication to let Ninject take care of calling your NinjectModule modules where you register your bindings.

@svallory just passing by to thanks. I'm actually new to Ninject and was getting this Exception while loading my application. Removed duplicated NinjectWebCommon class and worked! ;)

@svallory This was Helpfull Thanks ^^.