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 {}
ProcessTypeGetTypeDataflow gets called for the derived type D, but nothing applies the annotations on B. This logic doesn't do it because it assumes B's annotations were already applied, and so doesn't keep B's members while processing D:
|
if (type.HasBaseType) |
|
{ |
|
var baseAnnotation = flowAnnotations.GetTypeAnnotation(type.BaseType); |
|
var annotationToApplyToBase = Annotations.GetMissingMemberTypes(annotation, baseAnnotation); |
|
|
|
// Apply any annotations that didn't exist on the base type to the base type. |
|
// This may produce redundant warnings when the annotation is DAMT.All or DAMT.PublicConstructors and the base already has a |
|
// subset of those annotations. |
|
reflectionMarker.MarkTypeForDynamicallyAccessedMembers(origin, type.BaseType, annotationToApplyToBase, type.GetDisplayName(), declaredOnly: false); |
|
} |
DAM on type is supposed to ensure that
GetTypecalled 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.ProcessTypeGetTypeDataflowgets 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:runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
Lines 147 to 156 in 4dd997d