Asp.net mvc 2 Ninject 2和MVC2.0

Asp.net mvc 2 Ninject 2和MVC2.0,asp.net-mvc-2,ninject,Asp.net Mvc 2,Ninject,我已经将一个项目从VS2008和MVC1更新为VS2010和MVC2。我对Ninject在区域内找不到控制器有问题 这是我的global.asax.cs文件: 名称空间网站 { //注:有关启用IIS6或IIS7经典模式的说明, //拜访http://go.microsoft.com/?LinkId=9394801 公共类MVC应用程序:NinjectHttpApplication { 公共静态标准内核; 公共静态无效注册表项(路由收集路由) { routes.IgnoreRoute(“{res

我已经将一个项目从VS2008和MVC1更新为VS2010和MVC2。我对Ninject在区域内找不到控制器有问题

这是我的global.asax.cs文件:

名称空间网站
{
//注:有关启用IIS6或IIS7经典模式的说明,
//拜访http://go.microsoft.com/?LinkId=9394801
公共类MVC应用程序:NinjectHttpApplication
{
公共静态标准内核;
公共静态无效注册表项(路由收集路由)
{
routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
routes.MapRoute(
“余额”,
“余额/{action}/{month}/{year}”,
新建{controller=“Balance”,action=“Index”,month=DateTime.Now.month,year=DateTime.Now.year}
);
routes.MapRoute(
“默认值”,//路由名称
“{controller}/{action}/{id}”,//带参数的URL
新的{controller=“Login”,action=“Index”,id=”“}//参数默认值
);
}
/*
受保护的无效应用程序\u Start()
{
RegisterAllAreas();
注册地址(RouteTable.Routes);
//初始化NHProfiler,以便您可以查看查询的情况
hibertingrhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
}
*/
Application Started()上受保护的覆盖无效
{
注册地址(RouteTable.Routes);
RegisterAllAreas();
RegisterAllControllersIn(Assembly.getExecutionGassembly());
}
受保护的无效应用程序\u错误(对象发送方,事件参数e)
{
var errorService=NinjectKernel.Get();
errorService.LogError(HttpContext.Current.Server.GetLastError().GetBaseException(),“AppSite”);
}
受保护的覆盖IKernel CreateKernel()
{
if(NinjectKernel==null)
{
NinjectKernel=新的标准内核(新的ServiceModule());
}
返回内核;
}
}
公共类ServiceModule:NinjectModule
{
公共覆盖无效负载()
{
Bind().To().InRequestScope();
绑定()到();
绑定().To().InSingletonScope();
Bind().ToMethod(ctx=>
ctx.Kernel.Get().GetSessionFactory())
.InSingletonScope();
绑定()到();
Bind().ToMethod(ctx=>ctx.Kernel.Get().GetSession());
}
}
}
访问/controllers文件夹中的控制器工作正常,但访问/Areas/Member/Controller中的控制器会引发以下错误:

Server Error in '/' Application.

Cannot be null
Parameter name: service

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Cannot be null
Parameter name: service

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 
[ArgumentNullException: Cannot be null
Parameter name: service]
Ninject.ResolutionExtensions.GetResolutionIterator(IResolutionRoot root, Type service, Func`2 constraint, IEnumerable`1 parameters, Boolean isOptional, Boolean isUnique) +193
Ninject.Web.Mvc.NinjectControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +41
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +124
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8771488
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Version Information: Microsoft .NET Framework Version:4.0.30128; ASP.NET     Version:4.0.30128.1
此请求的Url为/Member/Controller/,如果我也更改了Url/Controller,则控制器将触发,但我得到一个错误,即系统无法在路径/视图中找到该视图

当它应该在/区域/成员/视图中查看时


我要么在升级过程中做错了什么,要么我错过了什么,我就是不知道是什么。我已经花了3天时间试图解决这个问题…

从核心更新,我刚刚提交了一个修复程序:


-Ian

我在使用Castle Windsor时也遇到同样的错误。@Carles很高兴知道这不仅仅是我。你应该能够在NinjectControllerFactory.GetControllerInstance上设置断点,你能再次检查请求URL并报告吗?@Ian谢谢你,如果我有时间,我会在这个周末尝试检查它。