Add documentation for RCW marshalling - #2512
Open
Sergio Pedri (Sergio0694) wants to merge 1 commit into
Open
Conversation
Sergio Pedri (Sergio0694)
requested a review
from Manodasan Wignarajah (manodasanW)
August 5, 2026 22:48
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sergio Pedri (Sergio0694)
force-pushed
the
user/sergiopedri/rcw-marshalling-docs
branch
from
August 5, 2026 22:56
cf654a4 to
9c97feb
Compare
Adds `docs/rcw-marshalling.md`, explaining how CsWinRT 3.0 creates RCWs when marshalling native Windows Runtime objects to managed, and links it from the existing COM interop guide. Nothing so far documented the decision logic in `WindowsRuntimeComWrappers.CreateObject`, which is the part people most often ask about: why an object sometimes comes back as a fully typed projection and sometimes as an opaque wrapper, and how much of that depends on the static type at the callsite. The document covers: - The marshaller entry points, and which of the two static callbacks each one supplies, including the fact that ordinary generated non-generic interfaces are marshalled through the callback-free entry point. - The CCW unwrap fast path and the existing-wrapper cache hit, both of which short-circuit the ladder entirely. - The decision ladder itself, as a diagram plus a walkthrough of each rung. - When 'GetRuntimeClassName' is and is not called, and what its result is used for. - How the infrastructure behaves for missing, unrecognised, and wrong runtime class names, separating the cases that always degrade safely from the recognised-but-wrong names that are trusted by design. - Four worked scenarios. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15b56f71-7292-4049-bf75-17f6198d7446
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
docs/rcw-marshalling.md, a conceptual guide to how CsWinRT 3.0 creates RCWs when marshalling native Windows Runtime objects to managed, and links it from the existing COM interop guide.Note
This targets #2511 rather than
staging/3.0, because the documentation describes the re-entrancy behaviour as fixed by that PR. It should be merged after it.Motivation
Nothing currently documents the decision logic in
WindowsRuntimeComWrappers.CreateObject, which is the part people most often ask about: why a native object sometimes comes back as a fully typed projection and sometimes as an opaque wrapper, whenGetRuntimeClassNameis consulted, and how the answer depends on the static type at the callsite. The logic is well commented in the source, but those comments are spread across several files and assume a lot of surrounding context.This came out of exactly that question being asked, and is written to be shareable with people who want to understand the model without reading the implementation.
Changes
docs/rcw-marshalling.md: new document covering the marshaller entry points and which of the two static callbacks each one supplies (including the fact that ordinary generated non-generic interfaces go through the callback-free entry point, while generic instantiations and selected manually-projected interfaces have callbacks); the CCW unwrap fast path and the existing-wrapper cache hit, which short-circuit the ladder entirely; the decision ladder itself as a Mermaid diagram plus a walkthrough of each rung; whenGetRuntimeClassNameis and is not called and what its result is used for; how the infrastructure behaves for missing, unrecognised and wrong runtime class names; and four worked scenarios.docs/interop.md: link to the new document from the "Create RCW" section.Notes
The resilience section deliberately separates two cases that are easy to conflate. Names we cannot resolve always degrade safely, costing specialization rather than correctness. Names we can resolve are trusted, so a native object reporting a wrong but known runtime class name can throw or yield an unexpected type — which is precisely why
TryCreateObjectis consulted before the type map, and why theIStringable/Windows.Foundation.Urioverride exists.The document is documentation only and does not change any behaviour.