Skip to content

Allow IStream to marshal from native to managed#369

Merged
tmat merged 3 commits intodotnet:mainfrom
asundheimMSFT:main
Nov 5, 2025
Merged

Allow IStream to marshal from native to managed#369
tmat merged 3 commits intodotnet:mainfrom
asundheimMSFT:main

Conversation

@asundheimMSFT
Copy link
Contributor

Overview

A recent change dotnet/symreader-portable#573 fixed marshalling IStream when the interface typed the parameters as object, but it turns out there are some APIs that explicitly mark the params as IStream and thus they flow through the ComStreamWrapper.Marshaller, which stubbed out ConvertToManaged with NotSupportedException.

Details

Since the debugger does need to call those APIs in EnC scenarios, this change implements ConvertToManaged with an identical strategy to the aforementioned PR (wrap the ComWrappers-marshallable IUnsafeComStream with something that implements IStream). UnsafeComStreamWrapper was copied over from symreader-portable.

The follow-up change to symreader-portable that bumps the dependency will also remove its copy of UnsafeComStreamWrapper in favor of this project's copy as symreader-portable already has IVT to this project.

Testing

Manually patched debugger with modified symreader and symreader-portable, verified we can marshal the IStream through an API like ISymUnmanagedENCUpdate::UpdateSymbolStore2

@AaronRobinsonMSFT
Copy link
Member

/cc @tmat

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Nov 4, 2025

/cc @jkoritzinsky @jtschuster

@tmat
Copy link
Member

tmat commented Nov 4, 2025

@asundheimMSFT Is there a way to test this code path in a unit test?

@asundheimMSFT
Copy link
Contributor Author

asundheimMSFT commented Nov 4, 2025

@asundheimMSFT Is there a way to test this code path in a unit test?

Added a test that manually marshals an IUnsafeComStream to IStream, then marshals it back to make an interop call. I'm not entirely satisfied with it since it's maybe not quite the same as marshalling a true native pointer but it at least exercises the ConvertToManaged modifications.

@tmat
Copy link
Member

tmat commented Nov 5, 2025

Thanks!

@tmat tmat merged commit 4ea649c into dotnet:main Nov 5, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants