Trim analysis doesn't track AssemblyQualifiedName of a known type

Open
#108,082 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp

Research direction

Reproduce the C# sample in the issue and inspect the trim analysis/dataflow handling of typeof(C).AssemblyQualifiedName. Compare it with the existing G("C, assemblyname") case; done means the known type name is tracked without IL2062 while the existing warning behavior remains correct.

Written by the indexing model from the issue text.

Description

area-Tools-ILLink
using System.Diagnostics.CodeAnalysis;

// warning IL2062: Value passed to parameter 's' of method 'G(String)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements.
G(typeof(C).AssemblyQualifiedName);

static void G([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string s) {
    Activator.CreateInstance(Type.GetType(s));
}

class C {}

This produces a warning because the dataflow analysis treats the result of typeof(C).AssemblyQualifiedName) as unknown. Instead it should track the result as a known type name and not produce any warnings (note that G("C, assemblyname") works and does not warn).

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.