StructureMap控制器问题

时间:2012-10-09 18:26:53

标签: c# asp.net-mvc asp.net-mvc-2 mvccontrib

当我的项目在本地计算机上以调试模式运行时,我收到以下错误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: 

1 个答案:

答案 0 :(得分: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以帮助确定导致问题的资源。