IL2079: Value stored in field 'target field' does not satisfy 'DynamicallyAccessedMembersAttribute' requirements. The field 'source field' 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

Cause

The target location declares some requirements on the type value via its DynamicallyAccessedMembersAttribute. Those requirements must be declared by the source value also via the DynamicallyAccessedMembersAttribute. The source value can declare more requirements than the target, if necessary.

Example

Type _typeField;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
Type _typeFieldWithRequirements;

void TestMethod()
{
    // IL2079 Trim analysis: value stored in field '_typeFieldWithRequirements' does not satisfy 'DynamicallyAccessedMembersAttribute' requirements. The field '_typeField' 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.
    _typeFieldWithRequirements = _typeField;
}