-
Notifications
You must be signed in to change notification settings - Fork 5k
Replace use of DAMT.All in ComponentModel with a more restricted set #114126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace use of DAMT.All in ComponentModel with a more restricted set #114126
Conversation
Note regarding the
|
Note regarding the
|
Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations |
@steveharter @eerhardt any opinion about re-annotating ComponentModel with a more restricted annotation? We used .All in multiple places of the framework whenever we needed to access private members in base type (e.g. At the time ComponentModel was annotated we didn't have The difference between .All and the replacement here is that .All means "all members, public and private, in bases and in implemented interfaces, and all implemented interfaces". The new annotation is "all members, public and private, in bases, and all implemented interfaces". I.e. we skip making members of interfaces available for reflection. So if someone previously did I reviewed uses of GetInterface/GetInterfaces here and doesn't look like we're affected. The only potential break here is that someone else could have taken a dependency on this being annotated .All. A mitigating factor right now is that |
The only public APIs where I see the new annotation flowing out of ComponentModel are:
I don't see any reason those APIs would need to support getting interfaces, so I'm in favor of taking the breaking change (especially with considering the mitigating factor you mentioned). |
@steveharter do you have any opinion about this? |
We're running out of time to make this change. If we don't do this for .NET10, we'll lose the mitigating factor I mentioned above (I'll repeat it below). The breaking change would be even more breaking. The measurements over at MichalStrehovsky/rt-sz#118 (comment) suggest this could be a 6.3% size savings for for our benchmark app TodosApi when using the options validator (see #106366 for context).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Replaces broad uses of DynamicallyAccessedMemberTypes.All
with targeted flag combinations to improve trimming behavior and maintainability.
- Introduces
AllMembersAndInterfaces
constants and applies them inTypeDescriptor
and related providers. - Updates
DbConnectionStringBuilder
and its ref file to explicitly list required member types. - Aligns annotations in both
System.ComponentModel.TypeConverter
andSystem.ComponentModel.Annotations
to use the new restricted sets.
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs | Replaced DAMT.All with explicit constructors/events/fields/etc. |
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs | Added AllMembersAndInterfaces constant and switched annotations |
src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/AssociatedMetadataTypeTypeDescriptionProvider.cs | Added AllMembersAndInterfaces constant and switched annotations |
Comments suppressed due to low confidence (3)
src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs:14
- Removal of the IL2113 suppression may reintroduce trimming warnings for reflection. Verify that the new attribute flags cover these cases or consider re-adding the suppression.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113:ReflectionToRequiresUnreferencedCode",
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs:37
- Add an XML doc comment for AllMembersAndInterfaces to explain which member types it includes and why this specific set is needed.
internal const DynamicallyAccessedMemberTypes AllMembersAndInterfaces =
src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/AssociatedMetadataTypeTypeDescriptionProvider.cs:14
- Add an XML summary comment for AllMembersAndInterfaces to clarify its purpose in this type description provider.
internal const DynamicallyAccessedMemberTypes AllMembersAndInterfaces =
/ba-g timeouts on android are known (#115955) |
This is technically a breaking change. Fixes #106366.