Description
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 nativeIUnknown*
through a user-definedpartial
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-definedpartial
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.
- Implement marshalling support for
BSTR
strings. AddBStrStringMarshaller
to source generator #69213 - Implement support for marshalling various types to Win32
VARIANT
s without typelib related support (no user-defined record types): Implement the ComVariant struct, the ComVariantMarshaller type, and generator integration #93635 - Implement support for marshalling arrays of various types to
SAFEARRAY
s- The minimum required support for WinForms' accessibility usage is defined here: https://docs.microsoft.com/en-us/windows/win32/winauto/variant-structure
- Optional: Implement stubbed-out support for
IDispatch
, or provide guidance for implementing stubbed-out support.- Per the documentation on Microsoft Active Accessibility, the
IDispatch
implementation can be stubbed out withE_NOTIMPL
errors: https://docs.microsoft.com/en-us/windows/win32/winauto/dual-interfaces--iaccessible-and-idispatch
- Per the documentation on Microsoft Active Accessibility, the
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.
- Provide a mechanism to easily activate a new COM object with a gesture similar to creating a new .NET object in C#. GeneratedComInterface/Class needs a way to register a factory method #111616
- Provide a mechanism to easily expose .NET objects for creation through COM activation, similar to the
EnableComHosting
switch in the SDK for built-in COM.
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-definedDispId
values - Add support for explicit
IDispatch
-based interfaces with generator-definedDispId
values - Stretch/Out-of-scope: Add
dynamic
compatibility forIDispatch
-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
orIDispatch
-related scenarios.
Features to consider
- Callouts for unmanaged <--> managed transitions. See Unmanaged-managed call transition callback #45118
Metadata
Metadata
Assignees
Labels
Type
Projects
Status