Skip to content

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Aug 27, 2025

Prevents hard to diagnose crashes caused by COM interop rehydrating wrong type.

Prevents hard to diagnose crashes caused by COM interop rehydrating wrong type.
@jkotas jkotas marked this pull request as ready for review August 27, 2025 02:00
@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 02:00
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 addresses COM interop type safety issues by adding explicit casting during the weak reference rehydration process. The changes prevent hard-to-diagnose crashes that can occur when COM interop rehydrates objects to the wrong type.

Key Changes:

  • Modified the COM-aware weak reference rehydration path to include runtime type casting
  • Refactored ComAwareWeakReference to expose the rehydration method with generic type parameter
  • Updated both generic and non-generic WeakReference classes to use the new type-safe rehydration approach

Reviewed Changes

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

File Description
src/libraries/System.Private.CoreLib/src/System/WeakReference.cs Updated non-generic WeakReference to use new type-safe COM-aware rehydration with explicit object casting
src/libraries/System.Private.CoreLib/src/System/WeakReference.T.cs Updated generic WeakReference to use new type-safe COM-aware rehydration with explicit T casting
src/libraries/System.Private.CoreLib/src/System/ComAwareWeakReference.cs Refactored to expose generic RehydrateTarget method with runtime casting and consolidated access through GetFromTaggedReference

@dotnet-policy-service
Copy link
Contributor

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

@jkotas
Copy link
Member Author

jkotas commented Aug 27, 2025

/backport to release/10.0

@github-actions
Copy link
Contributor

@github-actions github-actions bot locked and limited conversation to collaborators Sep 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants