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

RuntimeMethodHandle.GetFunctionPointer() should check if generic method is constructed #101664

Open
CyberAndrii opened this issue Apr 28, 2024 · 1 comment

Comments

@CyberAndrii
Copy link

CyberAndrii commented Apr 28, 2024

Description

Calling GetFunctionPointer() on a non-constructed generic method throws InvalidProgramException: Common Language Runtime detected an invalid program. A more helpful error message could be added.

Reproduction Steps

unsafe
{
    var func = (delegate*<void>) typeof(Foo)
        .GetMethod(nameof(Foo.Func))!
        .MethodHandle
        .GetFunctionPointer();
    
    func();
}

static class Foo
{
    public static void Func<T>()
    {
    }
}

Expected behavior

User friendly exception is thrown.

Actual behavior

InvalidProgramException is thrown.

Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at System.RuntimeMethodHandle.GetFunctionPointer() in /runtime/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs:line 829
   at Program.<Main>$(String[] args)

Regression?

No

Known Workarounds

Not applicable

Configuration

.NET 8 and 9
linux-x64

Other information

If the type itself is a generic type it throws System.InvalidOperationException: Could not execute the method because either the method itself or the containing type is not fully instantiated.. I think that's the correct exception to be thrown.

unsafe
{
    var func = (delegate*<void>) typeof(Foo<>)
        .GetMethod("Func")!
        .MethodHandle
        .GetFunctionPointer();
    
    func();
}

static class Foo<T>
{
    public static void Func()
    {
    }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 28, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 28, 2024
@danmoseley danmoseley added area-System.Reflection and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 28, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

@steveharter steveharter added bug and removed untriaged New issue has not been triaged by the area owner labels May 1, 2024
@steveharter steveharter self-assigned this May 1, 2024
@steveharter steveharter added this to the 9.0.0 milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants