The type InjectionPolicy does not have an accessible constructor

Jul 31, 2013 at 8:48 AM
Edited Jul 31, 2013 at 8:57 AM
So,

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 asp.net-MVC4 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=1.0.0.0, 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=1.0.0.0, 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)
Editor
Aug 1, 2013 at 4:18 AM
That is a bit strange. I'm wondering if there could be some resolves occurring before registration is complete?


~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Aug 1, 2013 at 6: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!
Editor
Aug 1, 2013 at 12: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
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Aug 28, 2013 at 12:44 AM
I am also having the same problem in asp.net 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 /> 
        </register>
Editor
Aug 28, 2013 at 1:33 AM
Can you start a new thread and post a complete example (code, configuration) to reproduce the issue?

Thanks,

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Mar 13 at 8:56 AM
Edited Mar 13 at 8:56 AM
Guys! We still are suffering with this issue, I've posted a pretty comprehensive report on this in this thread here:
https://unity.codeplex.com/discussions/538867

Please check it out.