Skip to content

Conversation

@jeffhandley
Copy link
Member

@jeffhandley jeffhandley commented Oct 9, 2025

Backport of #119584 to release/10.0

/cc @jeffhandley @steveisok @lewing

Customer Impact

  • Customer reported
  • Found internally

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

  • Yes
  • No

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 RuntimeType code paths with surgical changes that rely on MetadataUpdater.IsSupported conditions 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.

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>
@jeffhandley jeffhandley added this to the 10.0.0 milestone Oct 9, 2025
@jeffhandley jeffhandley self-assigned this Oct 9, 2025
Copilot AI review requested due to automatic review settings October 9, 2025 19:19
Copy link
Contributor

Copilot AI left a 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 MetadataUpdateDeletedAttribute class 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

Copy link
Member

@jkotas jkotas left a 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.

@steveisok steveisok changed the title [release/10.0] Add MetadataUpdateDeletedAttribute [release/10.0] Add MetadataUpdateDeletedAttribute and Reflection Filtering Oct 13, 2025
@jeffhandley jeffhandley assigned steveisok and unassigned jeffhandley Oct 13, 2025
Copy link
Member Author

@jeffhandley jeffhandley left a 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.

@steveisok steveisok added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 14, 2025
@steveisok
Copy link
Member

steveisok commented Oct 14, 2025

/ba-g all known issue filed #120577, #120577, #120577, #120577

@steveisok steveisok merged commit 7d43e0f into dotnet:release/10.0 Oct 14, 2025
151 of 159 checks passed
@jeffhandley jeffhandley deleted the jeffhandley/backport-119584 branch October 16, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants