Hi there, 
        
The issue DYNPROXY-ISSUE-128 was just created by cosborne (cosborne).
        
        Key: DYNPROXY-ISSUE-128
        Summary: Proxy without target passes wrong MethodInfo to interceptor
        Type: Bug
        Importance: High
        
        Description:
        I have a set of interfaces defined along the lines of the following:
public interface RootInterface
{
    string RootMethod();
}
public interface InterfaceA : RootInterface
{
    string CommonMethod();
}
public interface InterfaceB : RootInterface
{
    string CommonMethod();
}
The proxy is then created using:
var gen = new ProxyGenerator();
var proxy = 
(RootInterface)gen.CreateInterfaceProxyWithoutTarget(typeof(RootInterface), 
new[] { typeof(InterfaceA), typeof(InterfaceB) }, new MyInterceptor());
The MyInterceptor lazily instantiates an object that implements either 
InterfaceA or InterfaceB (but not both) based on data known only at runtime. It 
then invokes the intercepted method directly against this target using:
public void Intercept(IInvocation invocation)
{
    invocation.ReturnValue = invocation.Method.Invoke(GetTarget(), 
invocation.Arguments);
    Console.WriteLine("Intercepted");
}
If the target object is (only) an InterfaceB, and I call the following:
((InterfaceB)proxy).CommonMethod()
This throws a TargetException on the method invocation, as invocation.Method is 
*always* the method as defined (invocation.Method.DeclaringType) on InterfaceA 
even when called through a reference to InterfaceB as above.
Properties are affected in the same way.
It is possible for the proxy to determine through which particular interface a 
method is called in a setup as above by implementing the additional interfaces 
as explicit interface implementations and then to pass the correct MethodInfo 
to the interceptor, but DynamicProxy does not appear to do this.
        
For more, see 
http://support.castleproject.org/projects/DYNPROXY/issues/view/DYNPROXY-ISSUE-128
 
        
--
donjon
by Castle Stronghold
http://www.castle-donjon.com


-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Development List" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-devel?hl=en.

Reply via email to