> What's the Correct
> Way(tm) to call InvokeMember with the RealProxy-derived
> Interposer so [out] parameters are contained? Thanks
I never noticed it until now, but the .Net Framework implementation of
IMethodCallMessage.Args actually recalculates/recreates the argument list
array every time it's called. The semantics fly in the face of it being a
property, where one would expect that a reference to an existing object[]
would be returned. The result is that out and ref parameter modifications
get lost between the InvokeMember call and the call to create the
ReturnMessage.
Anyway, the fix is straightforward. The implementation of Interposer.Invoke
should look something like this:
public override System.Runtime.Remoting.Messaging.IMessage
Invoke( System.Runtime.Remoting.Messaging.IMessage message )
{
System.Runtime.Remoting.Messaging.IMethodCallMessage methodMessage =
(System.Runtime.Remoting.Messaging.IMethodCallMessage) message;
System.Reflection.MethodBase method = methodMessage.MethodBase;
object returnValue = null;
// Create a temporary to hold the argument list. This overcomes
// a peculiarity in the .Net Framework implementation of
// methodMessage.Args which seems to recalculate the object[]
// at every call.
object[] tempArgs = methodMessage.Args;
// Handle IInterposed methods/properties here. Right now, there is
// only one property, so don't do any extensive checking to determine
// the method being invoked.
if ( method.DeclaringType == typeof( IInterposer ) )
{
returnValue = m_target;
}
else
{
returnValue =
m_target.
GetType().
InvokeMember(
method.Name,
System.Reflection.BindingFlags.InvokeMethod,
null,
m_target,
tempArgs );
}
System.Runtime.Remoting.Messaging.ReturnMessage returnMessage =
new System.Runtime.Remoting.Messaging.ReturnMessage(
returnValue, tempArgs, tempArgs.Length,
methodMessage.LogicalCallContext, methodMessage );
return returnMessage;
}
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.