Skip to content

Fix cast when stream is IUnsafeComStream#573

Merged
tmat merged 2 commits intodotnet:mainfrom
asundheimMSFT:dev/asundheim/stream-cast
Aug 14, 2025
Merged

Fix cast when stream is IUnsafeComStream#573
tmat merged 2 commits intodotnet:mainfrom
asundheimMSFT:dev/asundheim/stream-cast

Conversation

@asundheimMSFT
Copy link
Contributor

@asundheimMSFT asundheimMSFT commented Aug 12, 2025

The switch to ComWrappers meant that marshalling parameters such as stream in

public int GetReaderFromPdbStream(
    [MarshalAs(UnmanagedType.Interface)]IMetadataImportProvider metadataImportProvider,
    [MarshalAs(UnmanagedType.Interface)]object stream,
    [MarshalAs(UnmanagedType.Interface)]out ISymUnmanagedReader reader)
{
    var comStream = stream as IStream ??
                throw new ArgumentException(null, nameof(stream));
    ...
}

would not play well with [ComImport] types in the runtime like IStream (hence the redefinition under IUnsafeComStream.) If you actually called from native->managed here with a valid COM IStream, the cast would fail.

This change adds a safe cast to IUnsafeComStream to shim IStream under the auspices of UnsafeComStreamWrapper (wrapper over both interfaces.)

@asundheimMSFT
Copy link
Contributor Author

@dotnet-policy-service agree company="Microsoft"

@asundheimMSFT please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@tmat
Copy link
Member

tmat commented Aug 12, 2025

@AaronRobinsonMSFT ptal

@tmat tmat merged commit 5069120 into dotnet:main Aug 14, 2025
8 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