Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence contains no elements - Bootstrapper #24

Closed
thomen opened this issue Jul 3, 2012 · 9 comments
Closed

Sequence contains no elements - Bootstrapper #24

thomen opened this issue Jul 3, 2012 · 9 comments

Comments

@thomen
Copy link

thomen commented Jul 3, 2012

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>();
    }
}

}

@remogloor
Copy link
Member

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

@svallory
Copy link

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

@remogloor
Copy link
Member

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 [email protected]

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.

@svallory
Copy link

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!

@svallory
Copy link

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

@ryno1234
Copy link

@svallory thank you for the update! This helped me

@mesoamerica
Copy link

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.

@jfaenomoto
Copy link

@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! ;)

@himonline33
Copy link

@svallory This was Helpfull Thanks ^^.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants