-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix DispatchProxy not working with in parameters #49214
Conversation
src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Christopher Watford <[email protected]>
MethodBuilder mdb = _tb.DefineMethod(mi.Name, MethodAttributes.Public | MethodAttributes.Virtual, CallingConventions.HasThis, | ||
returnParameter.ParameterType, returnReqMods, returnOptMods, | ||
paramTypes, paramReqMods, paramOptMods); |
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
ParameterInfo returnParameter = mi.ReturnParameter; | ||
Type[] returnReqMods = returnParameter.GetRequiredCustomModifiers(); | ||
Type[] returnOptMods = returnParameter.GetOptionalCustomModifiers(); |
There was a problem hiding this comment.
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
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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In line 430
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @wzchua LGTM
I've closed, reopened to restart the CI |
Resolves #47522