dotnet / dotnet/linker

Warning getting generated for lightup patterns

Open
#2,392 0 comments 0 reactions 0 assignees View on GitHub
area-Linker: DataFlow
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

```csharp
Type.GetType("TypeThatDoesntExist").GetMethod("Foo");
```

Above generates `C:\trimmedapp\Program.cs(4,5): Trim analysis warning IL2075: Program.$(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 https://github.com/dotnet/runtime/pull/61952.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.