You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Inconsistent behavior for Requires on attribute constructor #2529
When an attribute ctor has RequiresUnreferencedCode we normally warn on attribute instances. If an attributed member has RequiresUnreferencedCode, this normally silences the warning. However, the behavior is inconsistent for RUC on type:
In the analyzer, RUC on type silences warnings from attributes on the type, type but not for attributes on the type's members.
In the linker, RUC on type silences warnings from attributes on the type's members, but not for attributes on the type itself.
I think the linker behavior makes sense here because RUC on type is supposed to allow the type's members to require unreferenced code without producing a bunch of warnings, instead producing warnings on dynamic access to the RUC members. I think these warnings should cover all ways to get to the members' attributes too. The attribute on the type itself should warn because it's possible to get at the type (and its attributes) with reflection, and this doesn't produce any warning. @vitek-karas do you agree?
RUC on type externally behaves as if all static members and constructors have RUC
RUC on type suppresses warnings as if all methods in the type have RUC on them (so method bodies and attributes)
RUC on type does NOT suppress warnings about/on nested types in any way
In the linker RUC on type is implemented by code which only reacts to accessed to members - accessing a type is not even noticed by the linker. We should implement something similar to this in the analyzer.
Note that this should apply to all warnings produced by the attributes, not just having RUC on the .ctor. Attribute can have DAM annotations which can also produce warnings and so on.
Activity
vitek-karas commentedon Jan 21, 2022
Short version: Yes - I agree.
This forced me to finally merge a writeup on a related topic I had for a long time: https://github.com/dotnet/linker/blob/main/docs/design/DAM-on-type-and-RUC-interaction.md
The important bits:
In the linker RUC on type is implemented by code which only reacts to accessed to members - accessing a type is not even noticed by the linker. We should implement something similar to this in the analyzer.
Note that this should apply to all warnings produced by the attributes, not just having RUC on the .ctor. Attribute can have DAM annotations which can also produce warnings and so on.