ninject/ninject.extensions.interception — Issue #8: Use of inherited ConstructorArguments/Parameters causes DynamicProxyProxyFactory to fail.
Author: chillitom
Created: 2012-01-20 17:40:10+00:00
State: open

Use of inherited ConstructorArguments and other Parameters cause errors in intercepted classes that take constructor arguments.

Because the proxy factory doesn't perform any matching of constructor argument against the parameters list non-matching inherited parameters will cause Castle's ProxyGenerator to throw. The factory also passes all parameters to the generator not just ConstructorArguments, passing only explicit constructor arguments would probably make more sense.

```
System.ArgumentException : Can not instantiate proxy of class: Ninject.Extensions.Interception.DynamicProxyProxyFactoryTests+ClassWithConstructorArgs.
Could not find a constructor that would match given arguments:
System.String
Parameter name: constructorArguments

Stack Trace:
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(Type proxyType, List`1 proxyArguments, Type classToProxy, Object[] constructorArguments)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
at Ninject.Extensions.Interception.ProxyFactory.DynamicProxyProxyFactory.Wrap(IContext context, InstanceReference reference)
at Ninject.Extensions.Interception.Activation.Strategies.ProxyActivationStrategy.Activate(IContext context, InstanceReference reference)
at Ninject.Activation.Pipeline.<>c__DisplayClass2.b__0(IActivationStrategy s)
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable`1 series, Action`1 action)
at Ninject.Activation.Pipeline.Activate(IContext context, InstanceReference reference)
at Ninject.Activation.Context.Resolve()
at Ninject.KernelBase.<>c__DisplayClass13.b__f(IBinding binding)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
```
A quick and rather rough fix might be to filter out all inherited parameters, a full fix might involve using Ninject's constructor scoring and picking constructor arguments from the parameters list.

Will dig in a little more.