Skip to content

Trim Analyzer doesn't handle annotations on inferred generic arguments #86032

@vitek-karas

Description

@vitek-karas
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLink.NET linker development as well as trimming analyzers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions