You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
DynamicallyAccessedMemberTypes.Interfaces does not cover GetInterfaces on base type #2473
The call of GetInterfaces() on type.BaseType triggers:
/home/roji/projects/test/Program.cs(22,5): Trim analysis warning IL2075: Program.<<Main>$>g__GetDeclaredInterfaces|0_0(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The return value of method 'System.Type System.Type::get_BaseType()' 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. [/home/roji/projects/test/Test.csproj]
If all interfaces on type are preserved, all interfaces on its base type should be preserved as well. There may be a similar issue with other DynamicallyAccessedMemberTypes members as well.
@vitek-karas I'm running into this for DynamicallyAccessedMemberTypes.PublicFields - can you confirm that this (and other relevant annotations) are also propagated via BaseType?
Private member annotations are not propagated, because that's how reflection works. Meaning calling Type.GetMethods() (with any combination of binding flags) will never return private members on the base type. The annotations were designed to follow the same semantics as reflection binding.
Activity
marek-safar commentedon Jan 3, 2022
/cc @vitek-karas @MichalStrehovsky
vitek-karas commentedon Jan 3, 2022
Good catch - #2476 has the fix, we'll try to take it for 6.0.2xx.
vitek-karas commentedon Jan 7, 2022
Fixed by #2476 for 6.0.2xx.
roji commentedon Jan 7, 2022
@vitek-karas I'm running into this for DynamicallyAccessedMemberTypes.PublicFields - can you confirm that this (and other relevant annotations) are also propagated via BaseType?
vitek-karas commentedon Jan 7, 2022
Almost all public members should be propagated. The code for this is here:
linker/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
Lines 1275 to 1298 in 89ae0f0
Private member annotations are not propagated, because that's how reflection works. Meaning calling Type.GetMethods() (with any combination of binding flags) will never return private members on the base type. The annotations were designed to follow the same semantics as reflection binding.
roji commentedon Jan 7, 2022
Perfect, thanks @vitek-karas!
vitek-karas commentedon Jan 7, 2022
Note: Everything but the Interfaces should already work in 6.0... so if you see anything different, please let us know.