[release/6.0] Don't create a COM weak reference if the object is an aggregated COMWrappers RCW. #61283
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.
Backport of #61267 to release/6.0
/cc @jkoritzinsky
Customer Impact
The issue blocks users from using the
WeakReference
andWeakReference<T>
with managed types that inherit from WinRT native types and that implementIWeakReferenceSource
. This means that managed developers extending common WinRT types are likely blocked from creating managed weak references.Testing
New testing was added in this PR. The original issue was reproducible and with this change we've confirmed it is fixed. The mitigate is to follow the same behavior as from .NET Framework's support of WinRT—don't query for
IWeakReferenceSource
if the managed type is aggregated.Risk
Low. Although this does touch that code may be run in with managed
WeakReference
andWeakReference<T>
it is narrowly defined to only trigger when WinRT types are involved. This only impacts C#/WinRT and WinUI scenarios.