Type Mapping is present, but Unity refuses to resolve - very strange behavior, any help please?

Jun 18, 2010 at 8:50 PM
Edited Jun 19, 2010 at 8:06 PM

Could really use some fresh insight on this - I've been using Unity for about a year now, and have been trying to figure out this issue for a few days, to no avail..

Two assemblies/projects in play:

An Infrastructure project,which runs a bootstrapper-task class in another project (the 'app project')

The app project has an interface in it: IPatientMapping, and an implementation, PatientMapping.

The bootstrapper class gets called and registers this type mapping:

_container.RegisterType<IPatientMapping, PatientMapping> (); 

Debugging at runtime, just before the .Resolve call, shows that the registration is indeed there, in the .Registrations collection of the IUnityContainer (I have screenshots to show this)

Yet I get this error:  
Exception is: InvalidOperationException - The current type, Rem.Ria.PatientModule.Web.Mapping.IPatientMapping, is an interface and cannot be constructed. Are you missing a type mapping?

I can't see any reason why it's doing this - in the class I'm trying to resolve, it resolves other dependencies just fine.. only this one gives me a problem.

I removed all dependencies in the PatientMapping class' constructor, still no success.

Any ideas at all?

Thanks

--Details:

interface and class:

 

namespace Rem.Ria.PatientModule.Web.Mapping
{
    public interface IPatientMapping //: IDtoMapping<PatientDTO, Patient> {}
    {
        Patient MapDtoToDomain ( PatientDTO dto );      
    }

    public class PatientMapping : IPatientMapping
    {

 

class getting injected (a WCF service):

 

        public PatientService (
            IPatientRepository patientRepository,
            ISessionSource session,
            IPatientMapping patientDtoToDomainMapper )
        {

Stack Trace:

{Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Rem.Ria.PatientModule.Web.WebService.PatientService", name = "(none)".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The current type, Rem.Ria.PatientModule.Web.Mapping.IPatientMapping, is an interface and cannot be constructed. Are you missing a type mapping?

-----------------------------------------------

At the time of the exception, the container was:

 

  Resolving Rem.Ria.PatientModule.Web.WebService.PatientService,(none)

  Resolving parameter "patientDtoToDomainMapper" of constructor Rem.Ria.PatientModule.Web.WebService.PatientService(Rem.Domain.PatientModule.Repositories.IPatientRepository patientRepository, Rem.Infrastructure.DAL.ISessionSource session, Rem.Ria.PatientModule.Web.Mapping.IPatientMapping patientDtoToDomainMapper)

    Resolving Rem.Ria.PatientModule.Web.Mapping.IPatientMapping,(none)

 ---> System.InvalidOperationException: The current type, Rem.Ria.PatientModule.Web.Mapping.IPatientMapping, is an interface and cannot be constructed. Are you missing a type mapping?

   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:line 209

   at BuildUp_Rem.Ria.PatientModule.Web.Mapping.IPatientMapping(IBuilderContext )

   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 43

   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110

   at Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\BuilderContext.cs:line 220

   at Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilderCustomization\NamedTypeDependencyResolverPolicy.cs:line 51

   at BuildUp_Rem.Ria.PatientModule.Web.WebService.PatientService(IBuilderContext )

   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs:line 37

   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 43

   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110

   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 511

   --- End of inner exception stack trace ---

   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 515

   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 485

   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 173

   at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(IUnityContainer container, Type t, ResolverOverride[] overrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainerExtensions.cs:line 532

   at Rem.Infrastructure.WCF.UnityInjectionInstanceProvider.GetInstance(InstanceContext instanceContext, Message message) in D:\Projects\team03\REM-Trunk\Base\Rem.Infrastructure\WCF\UnityInjectionInstanceProvider.cs:line 34}

 

Jun 21, 2010 at 9:49 PM

I replied to your other thread.

Mar 11, 2011 at 4:04 PM
ctavares wrote:

I replied to your other thread.


Which is where?  Barren and abortive posts make me crazy.

Mar 14, 2011 at 3:47 AM

Here's the other thread.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com