7
votes

We are hitting the following error in some of our environments, seemingly after the app pool recycles.

An instance of IControllerFactory was found in the resolver as well as a custom registered provider in ControllerBuilder.GetControllerFactory. Please set only one or the other.

We are not using the ControllerBuilder to register our controller factory, only the IDependencyResolver as pointed out in the this blog

We are using Castle Windsor (seemingly unrelated), as our container, and in the Application_Start of the Global.asax, first registering all of our dependencies and calling the following to register the IDepencencyResolver.

DependencyResolver.SetResolver(new WindsorDependencyResolver(IoC));

What could be causing this exception? Any help would be appreciated.

2
Have you already registered through the DefaultControllerFactory?Kadir.K
This only happens when the app pool recycles, not when the application starts the first time?jeff.eynon
@jeff.eynon No. It happens after the app pool recycles, in the HttpApplication's Application_Start event.Jace Rhea
I'm not familiar with Castle Windsor (we use Unity as our IoC), but it it possible that somewhere in the WindsorDependencyResolver constructor that it sets the ControllerFactory on the ControllerBuilder as some sort of fallback or something?jeff.eynon
@jeff.eynon Thanks for the followup, I'll take a look at that.Jace Rhea

2 Answers

0
votes

Using the MVC DependencyResolver with Castle Windsor is not recommended as it has a design flaw: it does not release service instances when it should. See this article for a full explanation.

Instead, use the method illustrated in the Windsor documentation which uses a custom factory to inject dependencies into controllers.

0
votes

For information, I had the same error message (with ninject). I don't understand why because the application started well in other machine. I tried to clear caches... but error was still present. I had redo a checkout in my repository and it was OK...