IL2060: Call to 'System.Reflection.MethodInfo.MakeGenericMethod' cannot be statically analyzed by the trimmer
Cause
A call to MethodInfo.MakeGenericMethod(Type[]) cannot be statically analyzed by the trimmer.
Rule description
This can either be that the method on which the MakeGenericMethod(Type[]) is called cannot be statically determined, or that the type parameters to be used for the generic arguments cannot be statically determined. If the open generic method has DynamicallyAccessedMembersAttribute annotations on any of its generic parameters, the trimmer currently cannot validate that the requirements are fulfilled by the calling method.
Example
class Test
{
public static void TestGenericMethod<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>()
{
}
void TestMethod(Type unknownType)
{
// IL2060 Trim analysis: Call to 'System.Reflection.MethodInfo.MakeGenericMethod' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method
typeof(Test).GetMethod("TestGenericMethod").MakeGenericMethod(new Type[] { typeof(TestType) });
// IL2060 Trim analysis: Call to 'System.Reflection.MethodInfo.MakeGenericMethod' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method
unknownMethod.MakeGenericMethod(new Type[] { typeof(TestType) });
}
}
Tilbakemeldinger
Send inn og vis tilbakemelding for