Unactionable trim warnings on property/event with attribute that has RUC ctor
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start by reproducing the supplied C# example and review the trim-analysis paths used by the analyzer, ILC, and ILLink. Use the referenced ProviderSettings.cs case as an additional example. Done means property and event attributes with RequiresUnreferencedCode no longer produce unactionable warnings, while the existing method behavior remains covered.
Written by the indexing model from the issue text.
Description
The trim analysis tooling warns on members annotated with attributes whose ctors have RequiresUnreferencedCode:
using System.Diagnostics.CodeAnalysis;
var m = typeof(C).GetMethod("M");
var p = typeof(C).GetProperty("P");
var f = typeof(C).GetField("f");
var e = typeof(C).GetEvent("E");
class C {
[AttributeWithRUC]
public static void M() {}
[AttributeWithRUC]
public static int f;
[AttributeWithRUC]
public static int P { get; set; }
[AttributeWithRUC]
public static event Action E;
}
[RequiresUnreferencedCode("AttributeWithRUC")]
class AttributeWithRUCAttribute : Attribute {}
analyzer:
Program.cs(12,6): warning IL2026: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
Program.cs(18,6): warning IL2026: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
Program.cs(15,6): warning IL2026: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
Program.cs(9,6): warning IL2026: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
ILC:
ILC : Trim analysis warning IL2026: C.E: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
ILC : Trim analysis warning IL2026: C.E: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
ILC : Trim analysis warning IL2026: C.f: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
ILC : Trim analysis warning IL2026: C.P: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
ILC : Trim analysis warning IL2026: C.P: Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
ILC : Trim analysis warning IL2026: C.M(): Using member 'AttributeWithRUCAttribute.AttributeWithRUCAttribute()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. AttributeWithRUC.
(similar for ILLink - except ILLink warns for all kept members, whereas ILC only warns for reflectable members)
The warning on the method M can be bubbled up by annotating it with RequiresUnreferencedCode - then there will be a warning on the reference to M instead.
Fields/properties/events aren't supported attribute targets of RequiresUnreferencedCode, so they can't be annotated directly. If you instead add RequiresUnreferencedCode at the class level, this produces warnings at the access to the field/property/event. However, the warnings from the annotated property/event are still present, making it impossible to annotate this without suppressions.
This came up while annotating System.Configuration.ConfigurationManager - for example, if ConfigurationPropertyAttribute is annotated with RequiresUnreferencedCode, it warns here: https://github.com/dotnet/runtime/blob/82f8ac64b3e369411f4f1168da616fa9ab3b79d3/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ProviderSettings.cs#L47-L48
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·