ResolutionFailedException

Aug 22, 2011 at 6:38 AM

 

 We are getting ResolutionFailedException intermittently even though the component registered properly in unity container.

Code :

-- Register IErrorCodeProvider in container
container.RegisterType<IErrorCodeProvider, ErrorCodeProvider>();
objErrors = UnityServiceLocator.Current.Resolve<IErrorCodeProvider>().GetErrorList();

ContainerControlledLifetimeManager() is not specified during the register. Will there be any issue if we don't specify this? if not, what could be the issue of getting ResolutionFailedException.

Thanks in advance.

Aug 22, 2011 at 7:54 AM

Hi,

You must be resolving on the same container where you registered your mappings. There should be no issues, if you didn't specify a lifetime manager. The default life time manager would be TransientLifeTimeManager.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 22, 2011 at 9:13 AM

Correct. But, we are seeing ResolutionFailedException intermittently in production. any idea?

Aug 22, 2011 at 9:22 AM

I see. I can't tell exactly. What kind of application are you running? Is this only happening to your production environment? Can you provide us a quick overview of your application?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 22, 2011 at 9:37 AM

This is happening in all environment intermittently (Dev, Test, UAT and Production). But, we don't have exact repro steps. We implemented this unity in WCF service.  On Application Startup, the component will be registred in unity container. If any error encounter while executing API, we get the object from container. we are using 4.1 version unity dll.

objErrors = UnityServiceLocator.Current.Resolve<IErrorCodeProvider>().GetErrorList();

 

Aug 22, 2011 at 10:27 AM

Honestly, we haven't tried WCF with Unity yet, though I was thinking you might missing something here. Have you already implemented the steps found on this blog on your application?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 22, 2011 at 12:00 PM

Intermittent exceptions you can't reproduce sounds like a multi-threading problem to me. If you are accessing the container from inside a WCF service you should consider injecting the container itself into the service instead of using some kind of static service locator.

http://www.neovolve.com/post/2010/05/15/Unity-dependency-injection-for-WCF-services-e28093-Part-1.aspx

If you implement a custom ServiceHostFactory you can choose to inject Unity into service instances if you need to.