Add cast to ComAwareWeakReference rehydrate path#119132
Merged
jkotas merged 1 commit intodotnet:mainfrom Aug 27, 2025
Merged
Conversation
Prevents hard to diagnose crashes caused by COM interop rehydrating wrong type.
Contributor
There was a problem hiding this comment.
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
ComAwareWeakReferenceto expose the rehydration method with generic type parameter - Updated both generic and non-generic
WeakReferenceclasses 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 |
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
agocke
approved these changes
Aug 27, 2025
src/libraries/System.Private.CoreLib/src/System/ComAwareWeakReference.cs
Show resolved
Hide resolved
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17267267126 |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevents hard to diagnose crashes caused by COM interop rehydrating wrong type.