-
Couldn't load subscription status.
- Fork 5.2k
[release/10.0] Add MetadataUpdateDeletedAttribute and Reflection Filtering #120572
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
[release/10.0] Add MetadataUpdateDeletedAttribute and Reflection Filtering #120572
Conversation
This attribute is intended to be emitted only by Roslyn. Its intent is to be used by reflection as a filter to "remove" types and members that have been deleted during a hot reload session. Implements dotnet#118903 * Add ability to filter members in reflection and test --------- Co-authored-by: Tomas Matousek <tomat@microsoft.com>
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
This PR adds the MetadataUpdateDeletedAttribute to support Hot Reload scenarios by marking metadata entities for deletion. The attribute instructs Reflection to filter out deleted types and members when enumerating, preventing them from being visible after a Hot Reload operation has applied changes to the containing module.
- Adds new
MetadataUpdateDeletedAttributeclass with appropriate usage restrictions - Integrates deletion filtering logic into CoreCLR's RuntimeType reflection enumeration paths
- Implements comprehensive test coverage for member deletion scenarios across inheritance hierarchies
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| MetadataUpdateDeletedAttribute.cs | New attribute class for marking deleted metadata entities |
| System.Runtime.Loader.cs | Reference assembly API surface addition |
| RuntimeType.CoreCLR.cs | Core filtering logic integration in reflection member enumeration |
| RuntimeHandles.cs | Visibility changes to support metadata token access |
| RuntimeCustomAttributeData.cs | Visibility changes for attribute detection |
| RuntimeTypeMetadataUpdateHandler.cs | Handler for managing deletion filtering state |
| ApplyUpdateTest.cs | Comprehensive test implementation for deletion scenarios |
| Test project files | Supporting test infrastructure and configuration |
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.
This is a new feature in an area that does not have comprehensive end-to-end testing. It is likely that it will need follow up fixes to address regressions that users are going to hit with this change in the wild.
I am leaving it up to tactics to decide whether this risk is worth it.
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.
I support this coming in for .NET 10 with the expectation that the hot reload scenarios will continue to have more gaps to fill that this does not address, and there may be a bug tail on this particular enhancement as well.
The new attribute, the respect of it, and Roslyn emitting diagnostics if added to user code all look good to me.
Backport of #119584 to release/10.0
/cc @jeffhandley @steveisok @lewing
Customer Impact
Hot Reload needs to mark metadata entities with an attribute or flag that instructs Reflection to not return them when enumerating types or type members. With this new attribute, Reflection filters out all types and members marked with this attribute if any Hot Reload change has been applied to the containing module/type.
Related issues and PRs:
Regression
Testing
New tests were added to exercise this scenario, simulating a hot reload update that deletes a member, verifying the member is no longer visible through Reflection.
Risk
Medium to High. This adds new API surface, alters the
RuntimeTypecode paths with surgical changes that rely onMetadataUpdater.IsSupportedconditions to be performant/trimmed out, and integrates with Roslyn to emit the attribute while also raising diagnostics if customers apply the attribute to user code.It's anticipated there will be hot reload cases that escape this logic, but this targets the most common scenarios.