DispatchProxyAsync icon indicating copy to clipboard operation
DispatchProxyAsync copied to clipboard

Missing support for ref- and out args for sync calls

Open crystalgreen opened this issue 1 year ago • 1 comments

Async calls don't support ref- or out arguments but synchronous calls do. But this doesn't work in DispatchProxyAsync.

When calling via Invoke, those arg types should be supported but I get an exception. The original DispatchProxy does support it.

See my example on dotnetfiddle. Also try only out- args or only ref-args.

crystalgreen avatar Mar 13 '24 14:03 crystalgreen

[DispatchProxyAsync] is have a bag - the author incorrectly added the processing of out and ref parameters. Copying the parameters back occurs before calling the invoke method. Fix: move block in row 682 for (int i = 0; i < parameters.Length; i++) { if (parameters[i].ParameterType.IsByRef) { args.BeginSet(i); argsArr.Get(i); args.EndSet(i, typeof(object)); } } after row 707 il.Emit(OpCodes.Callvirt, invokeMethod); is now work fine There is also a bug with out parameters: out parameter values ​​are not passed to invoke comment row 627 if (!parameters[i].IsOut)

chekhlov avatar Nov 25 '25 08:11 chekhlov