Closed
Description
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()
{
}
}