Description
There appears to be no way to use UnsafeAccessor to run a nongeneric method when it has a generic overload with the same signature.
This fails in .NET 9 and 10, but succeeds in 8.
Reproduction Steps
using System.Runtime.CompilerServices;
class Program
{
static void Main()
{
// Throws System.Reflection.AmbiguousMatchException: 'Ambiguity in binding of UnsafeAccessorAttribute.'
Example(null);
}
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
private static extern void Example(ContainingClass? _);
}
class ContainingClass
{
private static void Example() { }
private static void Example<T>() { }
}
Expected behavior
The nongeneric method is invoked.
Actual behavior
The runtime throws AmbiguousMatchException.
Regression?
Yes, it worked in 8 and fails in 9 and 10.
Known Workarounds
Use reflection if possible instead of UnsafeAccessor
Configuration
No response
Other information
No response