Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ArnaudB88 opened this issue Apr 30, 2019 · 0 comments
Open

Comments

@ArnaudB88
Copy link

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());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant