有没有可能让RealProxy看起来像这样:
public InterfaceProxy(object instance, params Type[] interfaces)并可以通过远程处理公开所有这些interfaces,将调用委托给instance,即使实例不是MarshalByRefObject也是如此
目前我遇到了一个问题,proxy接收到对InitializeLifetimeService的调用,无论我从它返回什么(包括null),我总是得到以下异常:
System.InvalidCastException:Return argument has an invalid type
at System.Runtime.Remoting.Proxies.RealProxy.ValidateReturnArg(Object arg, Type paramType)
at System.Runtime.Remoting.Proxies.RealProxy.PropagateOutParameters(IMessage msg, Object[] outArgs, Object returnValue)
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnmessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)发布于 2012-10-11 20:51:52
只要让你的类实现IRemotingTypeInfo即可。
伪代码看起来像这样:
class InterfaceProxy : RealProxy, IRemotingTypeInfo
{
// snip all the basics
bool IRemotingTypeInfo.CanCastTo(Type fromType, Object o)
{
return interfaces.Contains(fromType);
}
}https://stackoverflow.com/questions/8426150
复制相似问题