The type InjectionPolicy does not have an accessible constructor

Jul 31, 2013 at 9:48 AM
Edited Jul 31, 2013 at 9:57 AM

We have a large application (many, many tiers) and they all use unity. We also use interface interception with unity to achieve logging.
The type InjectionPolicy does not have an accessible constructor
I get this error very erratically, in most cases the resolution works perfectly, and there is a huge object graph to construct. An exception with this message just shows up and then breaks everything, and it's very random!

I got the exception, this is a section of the exception from an application that uses Unity for the api controllers:
      Resolving Gideon.App.Common.SystemDefaultsManager`1[Gideon.Data.SystemEntity.Models.Settings.OpenPatientColumns],(none) (mapped from Gideon.App.Common.ISystemDefaultsManager`1[Gideon.Data.SystemEntity.Models.Settings.OpenPatientColumns], (none))
      Resolving parameter "repo" of constructor Gideon.App.Common.SystemDefaultsManager`1[[Gideon.Data.SystemEntity.Models.Settings.OpenPatientColumns, Gideon.Data.SystemEntity, Version=, Culture=neutral, PublicKeyToken=null]](Gideon.Infrastructure.Common.ICorrelationInfo cinfo, Gideon.Data.SystemEntity.Repositories.Core.IRepository`1[[Gideon.Data.SystemEntity.Models.Settings.OpenPatientColumns, Gideon.Data.SystemEntity, Version=, Culture=neutral, PublicKeyToken=null]] repo)
        Resolving Gideon.Data.SystemEntity.Repositories.SystemDefaultsRepository`1[Gideon.Data.SystemEntity.Models.Settings.OpenPatientColumns],(none) (mapped from Gideon.Data.SystemEntity.Repositories.Core.IRepository`1[Gideon.Data.SystemEntity.Models.Settings.OpenPatientColumns], (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)
Aug 1, 2013 at 5:18 AM
That is a bit strange. I'm wondering if there could be some resolves occurring before registration is complete?

Randy Levy
Enterprise Library support engineer
Support How-to
Aug 1, 2013 at 7:33 AM
Thanks a lot for your reply.

We have a separate data structure across all tiers that houses registration maps (Type from and to), there is a wrapper over unity that will read this information and then consumers in our system can use it.

I've only given a snapshot of the dependency graph in the exception, there were a lot of other classes also request for.

If there were resolves before the registration then it should complain about those resolves right?

Also, what's worse is that it's just erratic. On some machines it shows up very often, on some machines it just doesn't show at all!
Aug 1, 2013 at 1:48 PM
If there are resolves before registration then I would expect to see typical error messages about an interface not being able to be constructed. However, registration is not thread safe so it's possible to have resolves occur during registration. In that scenario I would expect to see stranger (and intermittent) errors.

So, typically, all registrations would happen during startup and once startup was completed and registrations completed then the application would be ready to accept incoming requests. If any container reconfiguration needed to happen then it should be done in a thread-safe manner.

Randy Levy
Enterprise Library support engineer
Support How-to
Aug 28, 2013 at 1:44 AM
I am also having the same problem in mvc app. It works fine without policy injection ( I am trying to use HandlerAttribute and ICallHandler). It is very consistent in my case. I have the configuration in config file and load them during Global.asax at Application_start() event. If i put this piece of config value i am getting this error. Not sure how the thread safeness or resolving before registration would affect as things are all happening in startup.
        <register type="IServiceHelper" mapTo="ServiceHelper">
          <interceptor type="InterfaceInterceptor" />       
          <policyInjection /> 
Aug 28, 2013 at 2:33 AM
Can you start a new thread and post a complete example (code, configuration) to reproduce the issue?


Randy Levy
Enterprise Library support engineer
Support How-to
Mar 13, 2014 at 9:56 AM
Edited Mar 13, 2014 at 9:56 AM
Guys! We still are suffering with this issue, I've posted a pretty comprehensive report on this in this thread here:

Please check it out.