Support ComSourceGenerator-based ActiveX controls #10583
Description
.NET version
.NET 8
Did it work in .NET Framework?
Yes (using classic COM interop)
Did it work in any of the earlier releases of .NET Core or .NET 5+?
Works using the classic COM interop.
Issue description
TLB support and tooling isn't ready yet in .NET 8 so its understandable that there has been limited attention to support the new COM source generators in WinForms, but there is still desire (dotnet/runtime#66674 (comment)) to get it working eventually. I'm currently prototyping (Devolutions/MsRdpEx#97) a hand written binding for the Microsoft RDP Client, which is apparently only provided in form of an ActiveX control, so should be a decent usecase and test scenario for ActiveX support in WinForms against the new COM source generators (besides the custom MFC based controls we previously used for testing compatibility, I might also extend those to provide test coverage, not sure how well a RDP client control is suited for unit testing)
A few things to note so far, I'll probably add more as the prototype comes along:
- returning a ComWrappers instance from
CreateInstanceCore
makes WinForms fail to resolve its interfaces- according to the docs this is supported by the runtime, but its off by default and has to be opted-in and is not NativeAOT compatible, so I do not opt-in and do things manually
- it is possible to work around this by manually translating it to a classic interop COM object (__ComObject instance obtained via
Marshal.GetObjectForIUnknown
on the ComWrappers IUnknown pointer) - ideally WinForms will support either being returned here, maybe probing which variant it is or something, I'll experiment and see what I can get to work here
- passing a ComWrappers instance to
ConnectionPointCookie
makes WinForms fail to understand it- the current
ConnectionPointCookie
API is not well-suited to custom bindings since it wants an interface type for reflection - even if the event handler interface implements both ComWrapper and classic COM interfaces WinForms still fails
- the current
My primary goal of this issue will be tracking required changes to support getting the prototype running entirely with handwritten source generator bindings, I'll open a PR for suggested fixes once I figure out more about why WinForms fails interacting with ComWrapper based instances.
Steps to reproduce
Write COM source generator bindings against an ActiveX control and try to use it with WinForms AxHost