Skip to content

Warning getting generated for lightup patterns #2392

Open
@MichalStrehovsky

Description

@MichalStrehovsky
Type.GetType("TypeThatDoesntExist").GetMethod("Foo");

Above generates C:\trimmedapp\Program.cs(4,5): Trim analysis warning IL2075: Program.<Main>$(String[]): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. The return value of method 'System.Type.GetType(String)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\trimmedapp\trimmedapp.csproj].

We should ideally treat "GetType called with a known string that doesn't resolve to a type" differently from "GetType called with an unknown string".

The type might be missing because it's a lightup. This should not warn because the runtime behavior is going to be same (the type is missing before and after trimming). Hit in dotnet/runtime#61952.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions