Skip to content

Inconsistent warning behavior for RUC/RDC on base types #107660

@sbomer

Description

@sbomer

Our tooling produces warnings on an unannotated type derived from a type that has RequiresUnreferencedCode:

class Derived : Base // warning IL2109: Type 'Derived' derives from 'Base' which has 'RequiresUnreferencedCodeAttribute'.  Base.
{} // ILLink/ILC also warn about the default ctor calling the base ctor

[RequiresUnreferencedCode("Base")]
class Base {}

But the same is not true for RequiresDynamicCode (it only warns for the call to the base ctor). This allows the use of static members of the derived type. The following doesn't produce any warnings because the default ctor is unused:

Derived.StaticMethod();

class Derived : Base {
    public static void StaticMethod() {}
}

[RequiresDynamicCode("Base")]
public class Base {}

I think we should unify on the RequiresDynamicCode behavior. @dotnet/illink any opinions?

Related: #106796

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzers

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions