Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DispatchProxy not working with in parameters #49214

Merged
merged 3 commits into from
Apr 12, 2021

Conversation

wzchua
Copy link
Contributor

@wzchua wzchua commented Mar 5, 2021

Resolves #47522

Co-authored-by: Christopher Watford <[email protected]>
Comment on lines 412 to 414
MethodBuilder mdb = _tb.DefineMethod(mi.Name, MethodAttributes.Public | MethodAttributes.Virtual, CallingConventions.HasThis,
returnParameter.ParameterType, returnReqMods, returnOptMods,
paramTypes, paramReqMods, paramOptMods);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @wzchua , looks good to me.
To avoid side effects I would pass null for unnecessary parameters, plus i believe it's better to use the CallingConventions.Standard which was used by default in the previous call

Suggested change
MethodBuilder mdb = _tb.DefineMethod(mi.Name, MethodAttributes.Public | MethodAttributes.Virtual, CallingConventions.HasThis,
returnParameter.ParameterType, returnReqMods, returnOptMods,
paramTypes, paramReqMods, paramOptMods);
MethodBuilder mdb = _tb.DefineMethod(mi.Name, MethodAttributes.Public | MethodAttributes.Virtual, CallingConventions.Standard,
mi.ReturnType, null, null,
paramTypes, paramReqMods, null);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I thought it would be more correct for all the mods to be included.
I made a mistake with the CallingConventions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I thought it would be more correct for all the mods to be included.

Understand your motive, but adding those could affect performance, as we don't have a known issue with not adding them I prefer keep the existing behavior

Comment on lines 408 to 410
ParameterInfo returnParameter = mi.ReturnParameter;
Type[] returnReqMods = returnParameter.GetRequiredCustomModifiers();
Type[] returnOptMods = returnParameter.GetOptionalCustomModifiers();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all unneeded variables here and above

Suggested change
ParameterInfo returnParameter = mi.ReturnParameter;
Type[] returnReqMods = returnParameter.GetRequiredCustomModifiers();
Type[] returnOptMods = returnParameter.GetOptionalCustomModifiers();

Removed unneeded mods
@@ -394,9 +394,19 @@ internal void AddInterfaceImpl([DynamicallyAccessedMembers(DynamicallyAccessedMe
private MethodBuilder AddMethodImpl(MethodInfo mi, int methodInfoIndex)
{
ParameterInfo[] parameters = mi.GetParameters();
Type[] paramTypes = ParamTypes(parameters, false);
Type[] paramTypes = new Type[parameters.Length];
Copy link
Member

@krwq krwq Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ParamTypes still used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 430

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used on this line but it seems that it is also not needed there. I will create a PR for that.

Copy link
Member

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @wzchua LGTM

@krwq krwq closed this Apr 12, 2021
@krwq krwq reopened this Apr 12, 2021
@krwq
Copy link
Member

krwq commented Apr 12, 2021

I've closed, reopened to restart the CI

@krwq krwq merged commit 486757d into dotnet:main Apr 12, 2021
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@wzchua wzchua deleted the fix/dispatch-proxy-include-method-modreq branch July 24, 2021 04:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Add support for 'in' decorator on method parameters for DispatchProxy
6 participants