1

I have recently started working on an ASP.NET MVC project that uses Castle Windsor. The problem is, each time I try to debug the application, this part of code takes a couple of minutes to execute:

protected override IController GetControllerInstance(
    RequestContext requestContext, Type controllerType)
{
    if (controllerType == null)
    {
        throw new HttpException(404, "some error");
    }

    // this takes long...    
    return (IController)kernel.Resolve(controllerType); 
}

If anyone encountered a similar situation and could share a solution to this, it would br great, since this situation practically hold me from using debugger...

I'm using VS2012, the project is on .NET Framework 4.5 and the version of Castle.Core and Castle.Windsor is 3.1


EDIT: OK, I found that the problem was not related to the container, it was actualy a matter of NLog settings - in NLog.config I had internalLogLevel set to "Trace" - I changed the level to "Error" and everything runs smoothly. Sorry for taking time to anybody, who was trying to solve my issue...

matt137
  • 169
  • 1
  • 14
  • did you try to load the container in a cache during application start. I am using this kind of an operation with Unity IOC – Saravanan May 14 '13 at 08:18
  • no, actually I have not changed any code related to Castle after I was given this project – matt137 May 14 '13 at 08:26
  • this is how the container is registered: `private static readonly IWindsorContainer container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle"))); protected void Application_Start() { // ... var builder = new ContainerBuilder(); builder.RegisterElFinderConnector(); _container = builder.Build(); _container.SetAsElFinderResolver(); WindsorConfig.Register(container);` – matt137 May 14 '13 at 08:28
  • So does this load all the containers in the config file to your app memory. – Saravanan May 14 '13 at 09:02
  • 1
    Does it take a few minutes each time or just the first? My guess is, you've got enabled Symbol Server support in Visual Studio and your VS is trying to download/load symbols – Krzysztof Kozmic May 14 '13 at 10:27
  • It actually takes few minutes on the first request after I enable debugging and then like 10seconds when I request different controller - but a request to a previously accessed controller is quick. Also requesting different actions on a controller is happening quickly. In tools -> options -> debugging -> symbols the 'Microsoft Symbol Servers' is unchecked – matt137 May 14 '13 at 10:48
  • Does a new `kernel` instance get created on each request, or do you create a single instance for the duration of the application? – Steven May 14 '13 at 12:15
  • It comes from container, created like this: `private static readonly IWindsorContainer container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));` in MvcApplication class, so I guess theres only one instance for the whole duration BTW I noticed, that the section in web.config is actualy empty (). I'm not sure yet if this is of any importance here – matt137 May 14 '13 at 12:34
  • Consider answering your own question to avoid keeping it on unanswered – Marwijn May 17 '13 at 07:12

0 Answers0