public class TestType
{
[RequiresUnreferencedCode("Dangerous")]
public void Dangerous() {}
}
public static void InvokeDangerous<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(T instance)
{
typeof(T).GetMethod("Dangerous").Invoke(instance, Array.Empty<object>());
}
// IL2026 - Dangerous
InvokeDangerous<TestType>(new TestType());
// No warning
InvokeDangerous(new TestType());
When the generic argument is inferred, the analyzer doesn't react to it in any way and doesn't produce any diagnostics. See the above sample, calling a generic method with the argument explicitly specified produces diagnostics, but when it's inferred no diagnostics are produced.