Skip to content

Provide a COM source generator #66674

Open
@jkoritzinsky

Description

@jkoritzinsky

We plan to provide a COM source generator to enable developers to interoperate with unmanaged COM interfaces without using the built-in COM Interop subsystem as per our Source Generator COM design.

This issue tracks the various tasks that implementing this source generator will require. Not all of these tasks will be completed in .NET 7 (in fact this list intentionally includes significantly more work than we will do in .NET 7 to provide a roadmap over a few versions).

Checkpoint 1: MCG-replacement

  • Implement a ComObject type that implements any required infrastructure to provide implementations of a COM interface.
    • Lifetime management, QI storage
    • discovery of the interface implementations (likely IDynamicInterfaceCastable-related)
  • Create a ComObject instance that wraps a native IUnknown* through a user-defined partial ComWrappers-derived type.
  • Implement support for calling a native COM interface from managed code through a ComObject using the above functionality.
  • Implement creating an IUnknown* that represents a managed non-ComObject object through a user-defined partial ComWrappers-derived type.
  • Implement support for calling methods defined in a COM interface on a managed object from unmanaged code through an IUnknown* wrapper using the above functionality

Checkpoint 2: WinForms compatibility

WinForms is primarily IUnknown-based COM, but there is some usage of IDispatch-based COM, primarily in the accessibility space. We would like to help support making WinForms trim-friendly, so we want to provide these features in the generator to support them.

Checkpoint 3: Activation support

For parity with the built-in system, providing an easy mechanism for activating a COM object is desireable, if lower priority.

Checkpoint 4: IDispatch support

If we find enough demand, we should consider providing more extensive IDispatch support (excluding TLB-related dependencies)

  • Implement support for explicit IDispatch-based interfaces with well-defined DispId values
  • Add support for explicit IDispatch-based interfaces with generator-defined DispId values
  • Stretch/Out-of-scope: Add dynamic compatibility for IDispatch-based COM object wrappers.

Checkpoint 5: TLB support

  • TLBImp replacement: Provide a mechanism for generating the C# source that is consumed by the source-generator from a TLB (COM type library)
  • TLBExp replacement: Provide a mechanism for generating an TLB from the C# source generator and using the existing TLB embedding support to embed the TLB in the COM host when the COM host is enabled.
  • Provide guidance for using TLB information in VARIANT or IDispatch-related scenarios.

Features to consider

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bottom Up WorkNot part of a theme, epic, or user storyEpicGroups multiple user stories. Can be grouped under a theme.area-System.Runtime.InteropServicestrackingThis issue is tracking the completion of other related issues.

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions