Skip to content

[NativeAOT] FormatException instead of ArgumentException in MethodBase.GetMethodFromHandle #113016

Closed
@TickThunder

Description

@TickThunder

Description

The JIT throws the correct exception, but NativeAOT does not. And the if condition should use IsGenericType instead of IsConstructedGenericType to be consistent with the JIT and Mono.
like this 1e51807

Reproduction Steps

public class Test<T>
{
    public void f(int a)
    {
        Console.WriteLine(a);
    }
}
public static partial class Program
{
    public static void Main(string[] args)
    {
        MethodBase.GetMethodFromHandle(typeof(Test<int>).GetMethod("f").MethodHandle);
    }
}

Expected behavior

System.ArgumentException:“Cannot resolve method Void f(Int32) because the declaring type of the method handle PInvokeSamples.Test`1[T] is generic. Explicitly provide the declaring type to GetMethodFromHandle.”

Actual behavior

Unhandled Exception: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
   at System.ThrowHelper.ThrowFormatIndexOutOfRange() + 0x2b
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider, String, ReadOnlySpan`1) + 0x78b
   at System.String.FormatHelper(IFormatProvider, String, ReadOnlySpan`1) + 0x86
   at System.SR.Format(String, Object) + 0xb9
   at System.Reflection.Runtime.General.ReflectionCoreCallbacksImplementation.GetMethodFromHandle(RuntimeMethodHandle) + 0xdd

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions