Open
Description
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:
- Made privates in base types available (this was not expressible with the more granular annotation)
- 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:
- Size. The size impact can be significant, I just saw a 6+% size impact.
- 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