Skip to content

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Sep 19, 2025

Backport of #119869 to release/10.0

Customer Impact

  • Customer reported
  • Found internally

Unable to unload collectible assemblies after calling framework APIs that cache certain reflection MemberInfos. Fix #119697.

MemberInfo.IsCollectible is frequently used to determine whether the reflection objects can be cached unconditionally. It was returning wrong result (false instead of true) for shared generic methods and more specialized reflected types, that in turn caused the MemberInfo to be cached unconditionally and prevented unloading of collectible assemblies that it referenced.

Regression

  • Yes
  • No

Testing

New tests added to exercise the fixed behavior

Risk

Low

…otnet#119869)

Use ReflectedType instead DeclaringType since ReflectedType can be colletible even when DeclaringType is not.

These fixes support typical IsCollectible use case where the property is used to determine whether or how the reflection objects can be cached.

Fix dotnet#119697
@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 21:56
Copy link
Contributor

@Copilot 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 fixes the IsCollectible property implementation for reflection MemberInfo objects to correctly consider all references when determining collectibility. The change addresses an issue where certain shared generic methods and specialized reflected types were incorrectly returning false for IsCollectible, preventing proper unloading of collectible assemblies.

  • Changes the IsCollectible property implementation to use ReflectedTypeInternal instead of the declaring type
  • Updates test methods to be more comprehensive by testing all members instead of individual named members
  • Adds special handling for RuntimeMethodInfo to check both ReflectedTypeInternal and the method handle's collectibility

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
RuntimePropertyInfo.cs Updates IsCollectible to use ReflectedTypeInternal instead of m_declaringType
RuntimeMethodInfo.CoreCLR.cs Implements more comprehensive IsCollectible logic checking both ReflectedTypeInternal and method handle
RuntimeFieldInfo.cs Updates IsCollectible to use ReflectedTypeInternal instead of m_declaringType
RuntimeEventInfo.cs Updates IsCollectible to use ReflectedTypeInternal instead of m_declaringType
RuntimeConstructorInfo.CoreCLR.cs Updates IsCollectible to use ReflectedTypeInternal instead of m_declaringType
IsCollectibleTests.cs Refactors tests from Theory to Fact methods and tests all members comprehensively

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

@JulieLeeMSFT JulieLeeMSFT added the Servicing-approved Approved for servicing release label Sep 19, 2025
@jkotas jkotas merged commit fc48aeb into dotnet:release/10.0 Sep 20, 2025
131 of 132 checks passed
@jkotas jkotas deleted the iscollectible-backport branch September 20, 2025 01:20
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.

4 participants