DAM on type is supposed to ensure that GetType called on that type or any derived type will satisfy the DAM annotations. In this example, d.GetType() should keep public methods on the base type and produce a warning for the RUC method.
using System.Diagnostics.CodeAnalysis;
class Program {
public static void Main() {
RequirePublicMethods(d.GetType());
}
static D d = new();
static void RequirePublicMethods([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type t) {}
}
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
class B {
[RequiresUnreferencedCode("M")]
public virtual void M() {} // There should be a warning about reflection access (through DAM-on-type) to M
}
class D : B {}
DAM on type is supposed to ensure that
GetType
called on that type or any derived type will satisfy the DAM annotations. In this example,d.GetType()
should keep public methods on the base type and produce a warning for the RUC method.ProcessTypeGetTypeDataflow
gets called for the derived typeD
, but nothing applies the annotations onB
. This logic doesn't do it because it assumesB
's annotations were already applied, and so doesn't keepB
's members while processingD
: https://github.com/dotnet/runtime/blob/4dd997dc1344f64dce53d7233e7ab6d09ff186b2/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs#L147-L156