Edit

Share via


IL2091: 'target generic parameter' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'target method or type'. The generic parameter 'source target parameter' of 'source method or type' 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 met by those declared on the source value also via the DynamicallyAccessedMembersAttribute. The source value can declare more requirements than the source if necessary.

Example

void NeedsPublicConstructors<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TTarget>()
{
    // ...
}

void TestMethod<TSource>()
{
    // IL2091 Trim analysis: 'TTarget' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'NeedsPublicConstructors'. The generic parameter 'TSource' of 'TestMethod' 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.
    NeedsPublicConstructors<TSource>();
}

Fixing

See Fixing Warnings for guidance.