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

[mono][System.Reflection.Emit] Fix explicitly setting the return type on a dynamic method #95183

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

ivanpovazan
Copy link
Member

@ivanpovazan ivanpovazan commented Nov 23, 2023

Description

This PR fixes the support of SetReturnType and SetParameters in the MethodBuilder API with Mono, by properly setting the return type of the dynamic method only if it is non null value.

This was manifested in two scenarios:

  1. If the dynamic method return and parameter types are manually set in the following sequence:

     methodBuilder.SetReturnType(interfaceMethodInfo.ReturnType);
     methodBuilder.SetParameters(paramTypes);

    The subsequent call to SetParameters (which internally calls SetSignatureCore) would overwrite the set return type to null causing the method not to be considered as an implementation of a interface method. This scenario is used in https://github.com/dotnet/aspnetcore/blob/4dc81f80abd45cb5c2e04d3b742bc6755c1153ee/src/SignalR/server/Core/src/Internal/TypedClientBuilder.cs#L136-L137 causing ASP.NET test failures when using Mono.

  2. Setting explicit null as a return type via SetReturnType overwrites the default return type value which should be typeof(void)

    This scenario was covered with System.Reflection.Emit libraries tests

    method.SetReturnType(null);
    type.CreateType();
    VerifyReturnType(method, typeof(void));
    but was disabled for Mono as reported in: [mono] Tests failed: System.Reflection.Emit.Tests #2389

Verification

This fix was verified by enabling the disabled unit test (and verifying locally that it passes) and manually verifying that the repro-iclientproxy-vtable-fail as described in #94490 (comment) does not crash.


Fixes #94490

@ivanpovazan ivanpovazan added the area-VM-reflection-mono Reflection issues specific to MonoVM label Nov 23, 2023
@ivanpovazan ivanpovazan self-assigned this Nov 23, 2023
@ivanpovazan
Copy link
Member Author

Once this fix gets approved, we should consider backporting it to .net8 servicing release as it affects signalR users on RHEL.

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.

Thank you for the fix.

Once this fix gets approved, we should consider backporting it to .net8 servicing release as it affects signalR users on RHEL.

💯, this looks regression introduced in 8.0 with #78544

@ivanpovazan
Copy link
Member Author

/backport to release/8.0-staging

Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/7007281730

@ivanpovazan ivanpovazan modified the milestone: 8.0.x Nov 27, 2023
@ivanpovazan ivanpovazan merged commit 2bfa26c into dotnet:main Dec 6, 2023
136 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-VM-reflection-mono Reflection issues specific to MonoVM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mono][System.Reflection.Emit] VTable initialization failure for class implementing an interface
3 participants