Skip to content

NativeAOT: Dependency analysis support for generic method reflection #81204

Closed
@hez2010

Description

@hez2010

I hope ILCompiler dependency analysis can take generic pattern into account so that we don't need rd.xml for this case any longer:

// Here we have System.Array.IndexOf<System.Int32>(System.Int32[],System.Int32)
var method = typeof(Array).GetTypeInfo().GetMethod(nameof(Array.IndexOf), 1, BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, null, CallingConventions.Any, new[] { Type.MakeGenericMethodParameter(0).MakeArrayType(), Type.MakeGenericMethodParameter(0) }, null)!.MakeGenericMethod(typeof(int));
var array = new int[] { 3, 2, 1, 0 };
Console.WriteLine(method.Invoke(null, new object?[] { array, 0 }));

Current behavior without a rd.xml:

Unhandled Exception: EETypeRva:0x00306AF8(System.Reflection.MissingRuntimeArtifactException): MakeGenericMethod() cannot create this generic method instantiation because no code was generated for it: 'System.Array.IndexOf<System.Int32>(System.Int32[],System.Int32)'.

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions