سؤال

When ever my project is run in debug mode on a local machine, I get the following error Value cannot be null. Parameter name: key. I've tried to debug it to see whats causing the issue but I've had very little luck. When ever a view is requested this error is thrown but the page loads, I'm at loss at what is causing this issue.

I've included the the error message and stack trace below:

System.ArgumentNullException was unhandled by user code
  Message=Value cannot be null.
Parameter name: key
  Source=mscorlib
  ParamName=key
  StackTrace:
       at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
       at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key)
       at StructureMap.Util.Cache`2.get_Item(KEY key)
       at StructureMap.BuildSession.CreateInstance(Type pluginType)
       at StructureMap.Container.GetInstance(Type pluginType)
       at StructureMap.ObjectFactory.GetInstance(Type pluginType)
       at MvcContrib.StructureMap.StructureMapControllerFactory.CreateController(RequestContext context, String controllerName) in c:\builds\mvccontrib\src\MvcContrib.StructureMap\StructureMapControllerFactory.cs:line 13
       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)
  InnerException: 
هل كانت مفيدة؟

المحلول

Make sure that any CSS or JavaScript resources that are referenced on your page actually do exist at the locations specified. If the resource is not found, your StructureMapControllerFactory may attempt to get an instance of a controller that matches the route.

If your StructureMapControllerFactory looks something like this:

public class StructureMapControllerFactory : DefaultControllerFactory
{
    protected override IController GetControllerInstance(
        RequestContext requestContext, 
        Type controllerType)
    {
        return ObjectFactory.GetInstance(controllerType) as Controller;
    }
}

then you can inspect the requestContext.RouteData.Values to help identify which resource is causing the problem.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top