Skip to content

Fix exception marshalling for generated COM interfaces - #2549

Merged
Sergio Pedri (Sergio0694) merged 1 commit into
staging/3.0from
user/sergiopedri/exception-marshalling
Sep 7, 2026
Merged

Fix exception marshalling for generated COM interfaces#2549
Sergio Pedri (Sergio0694) merged 1 commit into
staging/3.0from
user/sergiopedri/exception-marshalling

Conversation

@Sergio0694

Copy link
Copy Markdown
Member

Summary

Add the missing UnmanagedToManagedOut annotation to RestrictedErrorInfoExceptionMarshaller so [GeneratedComInterface] can use it to marshal managed exceptions back to native callers.

Motivation

The marshaller only registered ManagedToUnmanagedOut, so configuring it as ExceptionToUnmanagedMarshaller caused the .NET COM source generator to report SYSLIB1051. Existing exception tests did not exercise this marshaller through generated COM interfaces, leaving this configuration unsupported without regression coverage.

Changes

  • src\WinRT.Runtime2\InteropServices\Marshalling\RestrictedErrorInfoExceptionMarshaller.cs: register UnmanagedToManagedOut alongside the existing ManagedToUnmanagedOut mode.
  • src\Tests\UnitTest\ComGenerationTests.cs: add generated COM interfaces and a managed implementation to cover both directions, including successful calls, HRESULT conversion, and preservation of the original exception. Force a unique RCW for the return-value case so the test crosses the generated COM boundary rather than unwrapping the managed object, and release COM references and thread error state after each case.

Register UnmanagedToManagedOut for RestrictedErrorInfoExceptionMarshaller and cover both generated COM directions with success and failure cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@Sergio0694
Sergio Pedri (Sergio0694) merged commit 8113435 into staging/3.0 Sep 7, 2026
13 checks passed
@Sergio0694
Sergio Pedri (Sergio0694) deleted the user/sergiopedri/exception-marshalling branch September 7, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CsWinRT 3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants