Description
Short Description
I expected a type on which the DynamicallyAccessedMembersAttribute is applied (with the enum value DynamicallyAccessedMemberTypes.All) to be excluded from trimming, and have all of its members preserved. However, this is not the case; instead private members are being removed. Repro created for inspection.
https://github.com/TheCakeMonster/Examples/tree/master/Issues/UnexpectedTrimming
Description
I have created two test libraries - one is a .NET Standard library, the other a .NET 6 library.
Each library contains a type that has the DynamicallyAccessedMembersAttribute applied using the DynamicallyAccessedMemberTypes.All enum value, indicating that all members are subject to dynamic access. However, the private instance method on each type is removed when the application is published. This is unexpected.
I have created a repro at https://github.com/TheCakeMonster/Examples/tree/master/Issues/UnexpectedTrimming
When the console app in this solution is run in debug mode, all of the console outputs are true, indicating that the private methods and the types they access are present. This is exactly what I expect (as trimming is not run) but is important in that it proves that the reflection code works.
When the console application is published and the published application is run, the flags all return false, instead of the second set - the ones associated with the class to which the attribute has been applied - continuing to return true.
Configuration
.NET 6 Preview 6
Dotnet --version output is as follows:
.NET SDK (reflecting any global.json):
Version: 6.0.100-preview.6.21355.2
Commit: 7f8e0d76c0
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\
Host (useful for support):
Version: 6.0.0-preview.6.21352.12
Commit: 770d630
Publishing is being performed using Visual Studio 2019 16.11 Preview 2, if that is relevant.
Regression?
This code makes use of a change to DynamicallyAccessedMembersAttribute that is only available in .NET 6, so it would not compile on .NET 5. This is new functionality in .NET 6, although it makes use of the trimming feature made more widely available in .NET 5.
The code makes use of the change made under issue #49465, which allows the DynamicallyAccessedMembersAttribute attribute to be applied to a class for the first time.