Unity: InjectionPolicy Type Cannot Be Built

This is a puzzle that I struggled with for hours. Here's the background:

  • We use Unity IoC in MVC4 web application
  • We have a couple of ApiControllers (IHttpController) and a bunch of regular controllers ( IController )
  • IControllers permission IControllers fine
  • The IHttpControllers resolution IHttpControllers been working fine for several months and now fails with a type resolution error with details of " The type InjectionPolicy cannot be constructed. You must configure the container to supply this value "
  • Both regular and Api controllers accept the ICustomerService dependency, which has an ICustomerRepository dependency, which in turn has an IClient dependency, but none of them is new or different.
  • Removing the dependencies of ICustomerService from ApiController solves the problem (but this interface is clearly configured and works everywhere)
  • We have an HttpControllerActivator that is registered with Unity and intercepts calls for the IHttpControllers solution - it fails in the container. Remove, even if it looks into the container, the controller is clearly there.

I searched for this error and found nothing. Has anyone seen this before or does it give you any clues as to what might be happening?

Thank you very much!

UPDATE: I narrowed it down to the permission of ICustomerRepository (again, working in all other threads). Error:

 Resolving Xxx.CustomerRepository,(none) (mapped from Xxx.ICustomerRepository, (none)) Resolving Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior,(none) Resolving parameter "policies" of constructor Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior(Microsoft.Practices.Unity.InterceptionExtension.CurrentInterceptionRequest interceptionRequest, Microsoft.Practices.Unity.InterceptionExtension.InjectionPolicy[] policies, Microsoft.Practices.Unity.IUnityContainer container) Resolving Microsoft.Practices.Unity.InterceptionExtension.InjectionPolicy[],(none) 
+6
source share

Source: https://habr.com/ru/post/955067/


All Articles