ResolutionFailedException - Exception occorred while: resolving

Sep 13, 2011 at 9:42 PM

Hi,

I am new to unity and just inherited a project that utilize unity 2.0.414.0 and Enterprise Library 5.0.  I have been able to compile the website but when I go to run it I get the error below which occurs when the code is  resolving an interface "this._proxy = webApp.RootContainer.Resolve<IRoleService>();",  I tried changing the code to "this._proxy = (IRoleService)webApp.RootContainer.Resolve(typeof(IRoleService));" but I still get the same error.  Any and all help in this matter is appreciated.

 

Inner Exception: "Exception has been thrown by the target of an invocation."

Stack Trace:

   at System.ServiceModel.Description.ServiceReflector.GetCustomAttributes(ICustomAttributeProvider attrProvider, Type attrType, Boolean inherit)
   at System.ServiceModel.Description.ServiceReflector.GetCustomAttributes(ICustomAttributeProvider attrProvider, Type attrType)
   at System.ServiceModel.Description.ServiceReflector.GetSingleAttribute[T](ICustomAttributeProvider attrProvider)
   at System.ServiceModel.Description.ServiceReflector.GetContractTypeAndAttribute(Type interfaceType, ServiceContractAttribute& contractAttribute)
   at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
   at System.ServiceModel.Description.TypeLoader.LoadContractDescription(Type contractType)
   at System.ServiceModel.ChannelFactory`1.CreateDescription()
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
   at OHE.FoundationModules.Services.WCFChannelManager.ChannelManagerSingleton.GetChannel[TChannel]() in C:\sscm\campus\FM5\Foundation Modules\Source\Service Layer\Services\OHE.FoundationModules.Services\WCFChannelManager\ChannelManagerSingleton.cs:line 112

Sep 14, 2011 at 7:14 AM

Hi,

Have you checked if you have already registered type mappings for the IRoleService?

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us

Sep 14, 2011 at 1:51 PM

Hi,

I don't see any register type mappings for the IRoleService in the code.  The other items being resolved here are strings and integres and I would guess there is no need to register their types as they are known type.  So since the IRoleService is a user define interface I need to register the type with the system.  This makes a lot of sense.  Can you kindly provide some guidence on how to go about registering the type for this object?  Do I need to use a specific tool or do I need to do this in a seperate class or do I need to do it in the configuration file?  Any and all help in this matter is appreciated.

 

Sep 14, 2011 at 3:41 PM

Hi,

Additionally, when I try to register the type just before the resolution I am being asked to provide a LifetimeManager and an array of InjectionMembers. Do I need to create a custom LifetimeManager class? Please see the code below.

WebClientApplication webApp = System.Web.HttpContext.Current.ApplicationInstance as WebClientApplication;

if (webApp == null)

{

throw new ProviderException(string.Format(CultureInfo.CurrentCulture, Resources.MembershipProvider_Only_Supports_WebClient));

}

if (webApp.RootContainer == null)

{

throw new ProviderException(string.Format(CultureInfo.CurrentCulture, Resources.RootContainer_can_not_be_null));

}

this._institutionId = webApp.RootContainer.Resolve<System.Int32>("InstitutionId");

this._appName = webApp.RootContainer.Resolve<System.String>("ApplicationName");

this._appId = webApp.RootContainer.Resolve<System.Int32>("ApplicationId");

//this._proxy = webApp.RootContainer.Resolve();

webApp.RootContainer.RegisterType<IRoleService>(); <-- Wants LifetimeManager and Injectionmember[]

this._proxy = (IRoleService)webApp.RootContainer.Resolve(typeof(IRoleService));

Sep 15, 2011 at 10:05 AM
Edited Sep 15, 2011 at 10:19 AM

Hi,

Resolving an interface means you are telling the Unity to provide you the concerete implementation of that interface. You must provide a type mapping when registering the interface otherwise an exception will be thrown on call to resolve. (http://msdn.microsoft.com/en-us/library/ff660853(v=PandP.20).aspx). Actually, LifeTime Manager and Injection Members are optional. LifeTimeManagers control how and when instances are created by the Unity container. Meanwhile the Injection Members allows you to provide values to your dependent objects on the current registered type. It really depends on the type you are registering (if it contains some dependent objects) and your overall requirements if you need to provide values for lifetime manager and injection members. Note that the default life time manager is the Transient LifeTime Manager.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us