Skip to content

Type.GetInterfaceMap(Type) is treated oddly by the trimming analyzers #108114

@KubaZ2

Description

@KubaZ2

Description

The second usage of GetInterfaceMap causes

IL2072: 'interfaceType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetInterfaceMap(Type)'. The return value of method 'System.Linq.Enumerable.First<TSource>(IEnumerable<TSource>)' 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.

while the first usage doesn't cause any warning.

I am not sure whether it's how it's supposed to be or it's an actual bug.

Reproduction Steps

object o = new();

var type = o.GetType();

var @interface = type.GetInterfaces().First();

_ = type.GetInterfaceMap(@interface).TargetMethods;

_ = type.GetInterfaceMap(@interface);

Expected behavior

I am not sure

Actual behavior

The warning is reported or not depending on whether some field is referenced or not

Regression?

No response

Known Workarounds

No response

Configuration

.NET 8

Other information

No response

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions