RodH257
RodH257

Reputation: 3632

What does this ninject controller factory error mean?

I've been working on my first MVC web application and since launching it I've been gettign this email which is automatically send from my Application_errror method in global.asax

Is it simply a 404 message? How would it be generated? I don't have any controller named Text, I've got HomeController and AssistanceController...

System.InvalidOperationException: The IControllerFactory 'FightTheFloods.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'text'.
  at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
  at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
  at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
  at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The IControllerFactory 'FightTheFloods.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'text'.
  at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
  at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
  at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
  at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Here is my controller factory code

public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel kernel = new StandardKernel(new FightTheFloodsServices());

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            if (controllerType == null)
                return null;
            return (IController)kernel.Get(controllerType);
        }


        /// <summary>
        /// Configuration for Ninject
        /// </summary>
        private class FightTheFloodsServices : NinjectModule
        {
            public override void Load()
            {
                Bind<IAssistanceManager>().To<AssistanceManager>();
                Bind<IAssistanceAlerter>().To<AssistanceAlerter>();
                Bind<ILocationHelper>().To<LocationHelper>();
                Bind<IUsersRepository>().To<UsersRepository>().WithConstructorArgument("connectionString", ConfigurationManager.
                                                                                                    ConnectionStrings[
                                                                                                        "AppDb"].
                                                                                                    ConnectionString);
                Bind<IAssistanceRequestRepository>().To<AssistanceRequestRepository>().WithConstructorArgument(
                    "connectionString", ConfigurationManager.
                                            ConnectionStrings[
                                                "AppDb"].
                                            ConnectionString);
            }
        }
    }

Upvotes: 0

Views: 2719

Answers (2)

John L
John L

Reputation: 305

I was experiencing a similar issue, fortunately the error messages were a little more helpful in my case:

"NinjectControllerFactory' did not return a controller for the name 'left_bg.gif'"
"NinjectControllerFactory' did not return a controller for the name 'Content'"

The only reference to 'left_bg.gif' in my application was in the site's main stylesheet. It was incorrectly pointing to the wrong folder. Pointing it to the correct folder fixed this error.

Fiddler helped me out with the second error. "Content" is a folder which contains a couple of subfolders ("Images", "Scripts", etc). Apparently my code was referring to a nonexistent image in the "/Content/Images/" folder which was causing a 500 error code in fiddler. So I removed the reference to that image, Fiddler reported no more problem, and the error ceased.

I can duplicate this at will, so I'd suggest using Fiddler to see if you have any errors on page refreshes, track those errors down, and rule them out as the cause. If you have a folder or resource named "text" (as indicated in the error you reported), it could be that NinjectControllerFactory is complaining about this, as was the case for me.

Upvotes: 2

dan_l
dan_l

Reputation: 1692

I have a similar GetControllerInstance , and I get various problems . Sometimes it will say Error activating WorkflowController More than one matching bindings are available. Activation path: 1) Request for WorkflowController

Suggestions: 1) Ensure that you have defined a binding for WorkflowController only once.

Sometimes it will says some value cannot be null .. and the annoyingly sometimes it will work successfully resolve the controller.

Upvotes: 0

Related Questions