Skip to content

Proposal: allow exception marshallers via '[return: MarshalUsing]' on generated COM interfaces methods without '[PreserveSig]' #109522

@Sergio0694

Description

@Sergio0694

Overview

This came up in microsoft/CsWinRT#1858. We'd like for the COM generator to support [return: MarshalUsing] to use custom marshallers for exceptions, so that CsWinRT could correctly allow using the necessary error propagation logic from generated COM interfaces. Currently, trying the code below doesn't do anything (but also it doesn't emit any warnings, it just silently does nothing).

API proposal

class GeneratedComInterfaceAttribute
{
+     public Type? ExceptionToUnmanagedMarshaller { get; set; }
}

Use case example

Users will be able to implement COM interfaces like this, implemented on WinRT-exposed types:

[Guid("6234C2F7-9917-469F-BDB4-3E8C630598AF")]
[GeneratedComInterface(
    Options = ComInterfaceOptions.ManagedObjectWrapper,
    ExceptionToUnmanagedMarshaller = typeof(ExceptionHelpersHResultMarshaller))]
public partial interface IFoo
{
    void Bar();
}

With ExceptionHelpersHResultMarshaller being a WinRT-compatible marshaller type we'll include in CsWinRT.

Risks

None that I can think of.

Alternatives

Developers can work around this by manually writing the entire vtable backend (eg. here).
This is extremely clunky and error prone.

Metadata

Metadata

Assignees

No one assigned

    Projects

    • Status

      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions