Skip to content

Update ActiveX and COM interop #97

@weltkante

Description

@weltkante

@awakecoding As discussed over at dotnet/runtime#66674 (comment) you were looking into using the new COM interop and being held back by the lack of TLB support. The TLB tooling however isn't critical, it's always been possible to write the interface declarations manually.

I did a very quick experiment (https://github.com/weltkante/MsRdpEx/tree/srcgen) to see into what problems I'm running and to give you a little bit of early feedback. I mostly copy/pasted the declarations from ILSpy and fixed issues as they presented, instead of properly porting the IDL of the TLB. Code not required for the simple scenario of setting up a RDP connection is also commented out.

Its not my intention to keep it it this way, next step is doing it properly, but it'll take some time and with holidays in between its nicer to show some early results instead of just waiting.

Things to note so far:

  • IDispatch is required for event handling and not provided by the source generator, but can be implemented manually. In the current state I just used old COM interop for the event handler interface to get the IDispatch support.
  • AxHost itself is still using the old COM interop, the documentation claims to support the code generators are supposed to be castable into old-style interfaces, but I couldn't get it to work. As a workaround I did manually conversion between the two styles of interop. Will have to research a bit more and maybe ask someone from the runtime team whats up with that, but its not much of an issue since a workaround is possible.
  • WinForms itself is still using old COM interop for accessibility, so in no case you'll be able to disable it entirely in .NET 8. Not sure how that affects Native AOT, I've seen people work on enabling Native AOT for WinForms in some scenarios so I assume it might still work. If not thats something to work with the WinForms team on improving. (I haven't tried Native AOT on the example code yet.)
  • Being source-compatible with the old generated library isn't possible, the source generators don't support properties so they have to be written as methods instead. Also as you already noted, the legacy tooling is sometimes generating APIs that are not possible to write in C# source. Personally I don't think its a big problem as I prefer handwritten declarations over the old tooling anytime, and its a one time effort to switch the library. Let me know what you think.
  • I noticed your intermediate library claims to be netstandard but has nonstandard dependencies, so is a bit of a hack. You'll want to move away from building a fake netstandard package and do a proper multitarget package because a .NET 8 source generated library won't be usable for Desktop Framework, so you can no longer have one DLL for all frameworks. Fixing the multitarget issues will require some changes to the repo build process, as currently everything outputs into a single folder regardless of target framework, so if you multitarget the different targets overwrite each other.

For now I'll work on just .NET 8 support on the branch but if you intend to keep supporting Desktop Framework (and/or older .NET Core versions) using the same handwritten API then you'll have to figure out how to do the necessary changes to support multitarget builds (shouldn't be hard). From my side it'll not be hard to write them in a way thats consumable from either target framework. I can put the interop declarations into your AxInterop.MSTSCLib as I've been doing so far, or provide the entire API as a separate nuget package external to this repo, I don't really have any preferences, you can let me know later what you prefer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions