0

当我的项目在本地机器上以调试模式运行时,我收到以下错误Value cannot be null. Parameter name: key。我试图调试它以查看导致问题的原因,但我运气不佳。当请求视图时,会抛出此错误但页面加载,我不知道是什么导致了这个问题。

我在下面包含了错误消息和堆栈跟踪:

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: 
4

1 回答 1

1

确保页面上引用的任何 CSS 或 JavaScript 资源确实存在于指定的位置。如果找不到资源,您StructureMapControllerFactory可能会尝试获取与路由匹配的控制器实例。

如果你StructureMapControllerFactory看起来像这样:

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

然后您可以检查requestContext.RouteData.Values以帮助确定导致问题的资源。

于 2013-01-02T01:03:14.727 回答