我在ASP.NET MVC3应用程序中初始化Castle Windsor时遇到异常。以下是我得到的例外情况:
Microsoft.Practices.ServiceLocation.ActivationException未处理 用户代码消息=尝试获取时发生激活错误 IController类型的实例,关键字“favicon.ico”
Source = Microsoft.Practices.ServiceLocation StackTrace: 在Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType,String key)in C:\首页\克里斯\项目\ CommonServiceLocator \主\ Microsoft.Practices.ServiceLocation \ ServiceLocatorImplBase.cs:行 57 at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance [TService](String 键入 C:\首页\克里斯\项目\ CommonServiceLocator \主\ Microsoft.Practices.ServiceLocation \ ServiceLocatorImplBase.cs:行 103 在AN.Core.Windsor.Web.WindsorControllerFactory.CreateController(RequestContext) requestContext,String controllerName)InnerException: system.missingMethodException而 Message =找不到方法:'Castle.Core.Internal.GraphNode [] Castle.Core.Internal.GraphNode.get_Dependers()'。 来源= AN.Core.Windsor.Web 堆栈跟踪: 在AN.Core.Windsor.Web.WindsorServiceLocator.DoGetInstance(Type serviceType,String key) 在Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType,String key)in C:\首页\克里斯\项目\ CommonServiceLocator \主\ Microsoft.Practices.ServiceLocation \ ServiceLocatorImplBase.cs:行 49 的InnerException:
这是我在global.asax中的初始化代码:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BootstrapWindsorContainer();
}
private static void BootstrapWindsorContainer()
{
_container = new WindsorContainer()
.Install(FromAssembly.InThisApplication());
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(_container));
var controllerFactory = new WindsorControllerFactory();
ControllerBuilder.Current.SetControllerFactory(controllerFactory);
}
答案 0 :(得分:2)
您需要将favicon.ico添加到要忽略的路线集合中。
例如:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("favicon.ico");
}