Skip to content

[API Proposal]: Mark DynamicallyAccessedMemberTypes.All as EditorBrowsable(Never) #114197

Open
@MichalStrehovsky

Description

@MichalStrehovsky

Background and motivation

When DynamicallyAccessedMemberTypes.All was added, we had:

		PublicParameterlessConstructor = 0x0001,
		PublicConstructors = 0x0002 | PublicParameterlessConstructor,
		NonPublicConstructors = 0x0004,
		PublicMethods = 0x0008,
		NonPublicMethods = 0x0010,
		PublicFields = 0x0020,
		NonPublicFields = 0x0040,
		PublicNestedTypes = 0x0080,
		NonPublicNestedTypes = 0x0100,
		PublicProperties = 0x0200,
		NonPublicProperties = 0x0400,
		PublicEvents = 0x0800,
		NonPublicEvents = 0x1000,
		Interfaces = 0x2000,

The .All annotation did everything the above mentioned ones do and on top of that:

  1. Made privates in base types available (this was not expressible with the more granular annotation)
  2. Made members of implemented interfaces available for reflection. This is a very niche use case and up until Propagate Type.GetInterfaces through dataflow analysis #114149 it wasn't even possible to take advantage of it without triggering trimming warnings.

Since then, we added more granular annotations to cover all use cases in 1 (#88512). The only extra thing that .All can do at this point is the members on interfaces.

People only very rarely have a need to use .All. But they use it a lot due to laziness. This has two problems:

  1. Size. The size impact can be significant, I just saw a 6+% size impact.
  2. Declaring one wants to reflect on more members than are actually needed leads to spurious warnings (e.g. Confusing AOT IL3035 error regarding Enums during Source Generation #112562 (comment)).

There is a huge value in being as specific as possible. The .All annotation is too wide.

API Proposal

namespace System.Diagnostics.CodeAnalysis;

[Flags]
public enum DynamicallyAccessedMemberTypes
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    All, // existing member
}

API Usage

Don't use the API.

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions