Dynamic member requirements
Development API in System.Diagnostics.CodeAnalysis, owned by System.Runtime.
DynamicallyAccessedMembersAttribute(memberTypes: DynamicallyAccessedMemberTypes)declares required members on aTypeInfoparameter, return value ([return: ...]), field, property, type/method generic parameter or TypeInfo method receiver. Read-onlyMemberTypesreturns those flags. The attribute constructor stores metadata; runtime execution of the constructor is not the retention mechanism.DynamicallyAccessedMemberTypesuses standard .NET flag values. Current native analysis acceptsNone(0),PublicParameterlessConstructor(1),PublicConstructors(3),PublicProperties(512), and their combinations. Other exposed values are reserved for unsupported member categories and fail native analysis when requested, includingAll.
See the generated attribute reference and flag reference. Supported flow, diagnostics and annotated runtime APIs describe the current boundaries. Unknown-flow warnings mean retention has not been proven. String resolution and arbitrary closed generic reflection targets remain unsupported; project retention files remain available.
Nongeneric class/interface implementations should repeat the same parameter and return
requirements as their interface declarations. The native backend reports DAM2005
on mismatches, including missing annotations; it does not silently strengthen the
interface contract or retain extra implementation bodies. Nongeneric reference-class
overrides are checked against their nearest base declaration with DAM2006, including
abstract declarations and closed generic base classes of nongeneric derived classes.
Generic derived classes, generic methods/interface mappings and value-type overrides
remain outside these checks. Generic parameter annotations do not extend this compatibility-check scope.
Annotated returns validate the producer and propagate declared requirements to callers. Unknown or insufficient returned values produce DAM2001; known type tokens infer roots.
Field writes and property setter values must satisfy their declared requirements; reads and getter returns carry them to consumers. Direct field-backed getters also propagate the property contract to storage. Indirect field addresses warn with DAM2007. HTTP JSON TypeInfo overloads declare the same flags as JsonSerializer.
A method-level annotation on an instance method of TypeInfo or its implementations applies to the receiver. Static methods and unrelated instance owners reject this target with DAM1001. Parameterless GetConstructors/GetProperties declare public constructor/property receiver requirements; corresponding implementations match.
Type and method generic parameters accept attributes before their names. Known
arguments at reachable generic calls and constructed type uses infer roots;
typeof(T) carries T's requirements. Unannotated or weaker forwarding parameters
warn with DAM2001. Generic JSON/HTTP JSON readers declare public parameterless
construction and public properties, matching their TypeInfo overloads. Complete
generic field/ancestry propagation and generic dispatch matching remain open.