Open
Description
Repro code
var generator = new ProxyGenerator();
var foo = generator.CreateInterfaceProxyWithoutTarget<IFoo>(new InspectInvocation());
foo.Bar();
public interface IFoo
{
void Bar() { }
}
public class InspectInvocation : IInterceptor
{
public void Intercept(IInvocation invocation)
{
Debug.Assert(invocation.InvocationTarget == null || invocation.MethodInvocationTarget != null); // will throw
}
}
Expected outcome
Unless I misunderstand the meaning of IInvocation.InvocationTarget
and IInvocation.MethodInvocationTarget
, I would expect the latter to point to a method of the former's type, if the former (IInvocation.InvocationTarget
) is non-null.
Actual outcome
MethodInvocationTarget
will throw an ArgumentNullException
due to the invocation's targetType
not being set.
Affected version(s)
Castle.Core starting at tag v5.2.0
/cc @dtchepak @zvirja @alexandrnikitin – this will likely matter for NSubstitute (in https://github.com/nsubstitute/NSubstitute/blob/4d258a28aba054ea18785d36b4bdd83da023aefb/src/NSubstitute/Proxies/CastleDynamicProxy/CastleInvocationMapper.cs#L11-L16) once we've published version 5.2.0 and you upgrade to that version.