Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unactionable trim warning on class with attribute that has RUC ctor #108501

Open
sbomer opened this issue Oct 2, 2024 · 1 comment
Open

Unactionable trim warning on class with attribute that has RUC ctor #108501

sbomer opened this issue Oct 2, 2024 · 1 comment
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Milestone

Comments

@sbomer
Copy link
Member

sbomer commented Oct 2, 2024

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:

[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

@sbomer sbomer added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Oct 2, 2024
@sbomer sbomer added this to AppModel Oct 2, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Oct 2, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

@agocke agocke added this to the 10.0.0 milestone Jan 14, 2025
@jeffschwMSFT jeffschwMSFT removed the untriaged New issue has not been triaged by the area owner label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers
Projects
Status: No status
Development

No branches or pull requests

3 participants