Skip to content

Error 'The type is not interceptable' for overwritten registrations #31

Open
@ArnaudB88

Description

@ArnaudB88

Hi,

The following error occurs when resolving the interface IADUtilities:

The type X.Business.Utilities.ADUtilitiesStubbed is not interceptable.
Parameter name: interceptedType


Exception occurred while:

·resolving type: 'ADUtilitiesStubbed'
•resolving type: 'IADUtilities' mapped to 'ADUtilitiesStubbed'

My setup:

public interface IAdUtilities {}
public class AdUtilities : IAdUtilities {}
public class AdUtilitiesStubbed : IAdUtilities {}

The registrations are build like:
1. Registration by convention:

var assemblies = System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, AssemblyConstants.AssemblyNamePrefix + "*.dll")
	.Select(f => System.Reflection.Assembly.LoadFile(f));

container.RegisterTypes(
	AllClasses.FromAssemblies(assemblies).Where(t => t.Namespace.StartsWith(AssemblyConstants.AssemblyNamePrefix, StringComparison.OrdinalIgnoreCase)),
	WithMappings.FromMatchingInterface,
	WithName.Default,
	t => lifetimeManager());

Result of this:

  • IAdUtilities is registered to AdUtilities and resolvable
  • AdUtilitiesStubbed is registered to itself and resolvable

2. Overwrite convention registrations by more advanced registration

container.RegisterType<IADUtilities, ADUtilities>(
	createLifetimeManager(),
	new Interceptor<InterfaceInterceptor>(),
	new InterceptionBehavior<LogBehavior>(),
	new InterceptionBehavior(new ImpersonationBehavior("mydomain", "myUsername", "myPassword", container.Resolve<Interfaces.ILogger>()))
);

Result of this:

  • IAdUtilities is registered to AdUtilities with 2 interceptors, and is resolvable
  • AdUtilitiesStubbed is not changed but is not resolvable anymore:

The type X.Business.Utilities.ADUtilitiesStubbed is not interceptable.
Parameter name: interceptedType


Exception occurred while:

·resolving type: 'ADUtilitiesStubbed'

This is probably caused by the fact that interception is registered on the FromType (here IAdUtilities).

3. For unit testing, the standard registrations should be overwritten by stubbed classes
container.RegisterType<Business.Interfaces.Utilities.IADUtilities, Business.Utilities.ADUtilitiesStubbed>(createLifetimeManager());

Result of this:

  • IAdUtilities is registered to AdUtilitiesStubbed, resolving fails:

The type X.Business.Utilities.ADUtilitiesStubbed is not interceptable.
Parameter name: interceptedType


Exception occurred while:

·resolving type: 'ADUtilitiesStubbed'
•resolving type: 'IADUtilities' mapped to 'ADUtilitiesStubbed'

It seems like the resolve happens in 2 steps:

  • IAdUtilities -> AdUtilitiesStubbed
  • AdUtilitiesStubbed -> AdUtilitiesStubbed (which fails to resolve)

Why does resolving the Stubbed class fail? This is not as expected (in old unity versions this works correct).
Can this be fixed please?

fyi: When reregistereing AdUtilitiesStubbed as last, resolve succeeds:
container.RegisterType<Business.Utilities.ADUtilitiesStubbed, Business.Utilities.ADUtilitiesStubbed>(createLifetimeManager());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions