Skip to content

Allow RequiresUnreferencedCode on classes and structs #1742

Closed
@eerhardt

Description

@eerhardt

Some types are inherently not trim compatible. Take, for example, BinaryFormatter. Virtually anything you do with the type is not going to be trim compatible.

Today, we only allow RequiresUnreferencedCodeAttribute on methods and constructors.

https://github.com/dotnet/runtime/blob/d2e1a86434d1c0b74d75604b4cf9fdca100108c3/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresUnreferencedCodeAttribute.cs#L14-L15

When trying to annotate the implementation of BinaryFormatter, it is causing almost every method in the library to be marked as RequiresUnreferencedCode. This is a lot of changes when just putting the attribute on a whole class would be a lot easier.

We should change the ILLinker to support RequiresUnreferencedCodeAttribute on classes and structs, and possibly interfaces.

@agocke @vitek-karas @MichalStrehovsky

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions