vs-streamjsonrpc icon indicating copy to clipboard operation
vs-streamjsonrpc copied to clipboard

Events raised by client proxy should set `sender` to proxy rather than JsonRpc object

Open AArnott opened this issue 3 years ago • 4 comments
trafficstars

The dynamic proxies generated on the client raise events with sender set to this.rpc (the JsonRpc object behind the proxy). For a proxy holder, particularly one that has never seen the JsonRpc object because it was created by another party, this may be unexpected.

I think the proxy sending this as the sender parameter is more appropriate so that someone's event handler can find the object on which the handler was added via the sender argument.

AArnott avatar Jan 11 '22 15:01 AArnott

@sharwell @RyanToth3 @CyrusNajmabadi @BertanAygun Do any of you think fixing this would break your existing code?

AArnott avatar Jan 11 '22 15:01 AArnott

We don't use a whole lot of event handlers in our RPC Contracts, in ServiceHub or elsewhere. After a quick search I don't see anywhere where this would affect me.

I do see however that in the AvailabilityChanged event handlers of a lot of the ServiceBroker classes that you've already overriden this behavior and done what you're describing above: https://devdiv.visualstudio.com/DevDiv/_git/DevCore/?path=src/clr/Microsoft.ServiceHub.Framework/RemoteServiceBroker.cs&version=GC3a218cd53dc99fb6e86d497bf2a475e28bd5b7c0&lineStyle=plain&line=611&lineEnd=611&lineStartColumn=157&lineEndColumn=112

RyanToth3 avatar Jan 11 '22 16:01 RyanToth3

I have an event handler in one of the RPC contracts I own but the only callers I know don't rely on "sender" parameter so this should be fine from my point of view as well.

BertanAygun avatar Jan 11 '22 17:01 BertanAygun

Adding @tmat

CyrusNajmabadi avatar Jan 11 '22 20:01 CyrusNajmabadi