-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Similar to #108454, but for attributes at the type level:
using System.Diagnostics.CodeAnalysis;
var c = typeof(C).GetCustomAttributes(false);
[AttributeWithRUC]
[RequiresUnreferencedCode("C")]
class C {}
[RequiresUnreferencedCode("AttributeWithRUC")]
class AttributeWithRUCAttribute : Attribute {}Trim analysis warning IL2026: C: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC
RequiresUnreferencedCode on C has no effect in this example (nor should it - it's just there to demonstrate that it doesn't silence the warning). There doesn't seem to be a way to annotate this to bubble up warnings to the caller.
A variation of this came up in #108464. There the issue is not with RUC on an attribute ctor, but with DebuggerDisplayAttribute:
Lines 10 to 11 in 81efcad
| [DebuggerDisplay("Count = {Count}")] | |
| public abstract class ConfigurationElementCollection : ConfigurationElement, ICollection |
This has the same problem when ConfigurationElementCollection is annotated with RequiresUnreferencedCode. Related: dotnet/linker#2122 worked around this issue for DebuggerDisplayAttribute strings that ILLink couldn't parse.
While #108454 could potentially be addressed by allowing RUC on properties/events, this issue seems to require a change in the warning model. I think the warning should point not to the annotated member, but to the place where the member (or maybe the attribute) is reflected over. Related: #103934
Metadata
Metadata
Assignees
Labels
Type
Projects
Status