Skip to content

Commit 486757d

Browse files
wzchuawatfordgnf
andauthored
Fix DispatchProxy not working with in parameters (#49214)
* Fix DispatchProxy not working with in parameters * Correct typo Co-authored-by: Christopher Watford <[email protected]> * Fixed Calling Convention Removed unneeded mods Co-authored-by: Christopher Watford <[email protected]>
1 parent d2cf673 commit 486757d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,19 @@ internal void AddInterfaceImpl([DynamicallyAccessedMembers(DynamicallyAccessedMe
394394
private MethodBuilder AddMethodImpl(MethodInfo mi, int methodInfoIndex)
395395
{
396396
ParameterInfo[] parameters = mi.GetParameters();
397-
Type[] paramTypes = ParamTypes(parameters, false);
397+
Type[] paramTypes = new Type[parameters.Length];
398+
Type[][] paramReqMods = new Type[paramTypes.Length][];
399+
400+
for (int i = 0; i < parameters.Length; i++)
401+
{
402+
paramTypes[i] = parameters[i].ParameterType;
403+
paramReqMods[i] = parameters[i].GetRequiredCustomModifiers();
404+
}
405+
406+
MethodBuilder mdb = _tb.DefineMethod(mi.Name, MethodAttributes.Public | MethodAttributes.Virtual, CallingConventions.Standard,
407+
mi.ReturnType, null, null,
408+
paramTypes, paramReqMods, null);
398409

399-
MethodBuilder mdb = _tb.DefineMethod(mi.Name, MethodAttributes.Public | MethodAttributes.Virtual, mi.ReturnType, paramTypes);
400410
if (mi.ContainsGenericParameters)
401411
{
402412
Type[] ts = mi.GetGenericArguments();

src/libraries/System.Reflection.DispatchProxy/tests/DispatchProxyTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ public static void Invoke_Ref_Out_In_Method()
603603
testRefOutInInvocation(p => p.Out(out _), null);
604604
testRefOutInInvocation(p => p.OutAttribute(value), "Hello");
605605
testRefOutInInvocation(p => p.Ref(ref value), "Hello");
606+
testRefOutInInvocation(p => p.In(in value), "Hello");
606607
}
607608

608609
private static void testRefOutInInvocation(Action<TestType_IOut_Ref> invocation, string expected)

src/libraries/System.Reflection.DispatchProxy/tests/TestTypes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface TestType_IHelloService
1919

2020
public interface TestType_IOut_Ref
2121
{
22+
void In(in string message);
2223
void Out(out string message);
2324
void Ref(ref string message);
2425
void InAttribute([In] string message);

0 commit comments

Comments
 (0)