1

I am currently using a COM Interop DLL, generated with tlbimp, to access a proprietary COM library from C# (net8), so no source code available (TLB embedded in DLL). It works, but stops me from using Trimming and AoT.

Now, I stumbled over the new ComWrapper API and its Source Generator, but can't find any resources explaining how to switch from the built-in COM Interop mechanism to the ComWrapper Source Generator with only a TLB/Interop Assembly available.

From my understanding, it should be somehow possible to generate C# classes from a COM library that make use of the new ComWrapper API and Source Generator. Similar to tlbimp but with code as a result instead of a binary.

I was thinking about disassembling the COM Interop to get the C# source and manually convert it to use the new ComWrapper API (related Q&A), but this seems like a lengthy and broken approach, especially for COM libaries with an excessive API.

What am I missing?

By the way: can I expect any performance improvements by using the ComWrapper API over the current COM Interop, or is it only about debugging, trimming and AoT?

7
  • 1
    tlbimp is about COM's Type Libraries, ie: metadata around COM interfaces, marshaling, coclasses etc. (PS: a tlb is optional in COM). .NET 5->9 just don't support these (apart from being able to embed it in binaries), they only support generating .NET "binding" for COM interfaces, either in a built-in way (not AOT compatible) or with the newer source generated way (AOT compatible, if done properly). You may see perf improvements, but it depends on details (and possibly on you :) Commented Nov 11 at 11:49
  • I think I understood that point @SimonMourier. But I am under the impression, that the result of tlbimp is the compiled result of what's needed as a base to use the new ComWrapper API. I found this post that followed my mentioned workaround of disassembling the Interop.dll, but only for a very tiny task, my COM library is huge, and without automation this is unfeasible. So what am I missing? Is there just no tool yet? If it is impossible, why does the workaround work? Commented Nov 12 at 9:50
  • 1
    Well, I don't think you fully do, .NET Core currently knows nothing about TLBs, that's about it. tlbimp is a .NET framework tool that was meant for .NET Framework and presumes built-in marshaling. If you want to use AOT, you'll have to find another more manual way. For example this tool github.com/dspace-group/dscom may work or may not. Details vary greatly depending on how your COM object's TLB/IDL is designed (automation types, etc.) Commented Nov 12 at 10:05
  • First of all, thanks for taking the discussion, I just recognized the idea in the other post is from you ;-) Please help me clear up my misunderstanding. I believe the TLB is a replacement for having the source code to be even able to use the COM library, where else should one know the available types from? So, if it is possible to disassemble the COM Interop, to use it as a starting point for the Source Generator, there must be a way to automate it... or not? Maybe all boils down to: How to wrap any COM Library for .NET using the new API without manually writing code? :-D Commented Nov 12 at 11:03
  • BTW: Using the TLB as input to such an automation, was just a rough idea I had. I am fine if the answer is: "There is no way", or "wait until this gap is closed (probably by Microsoft)"... In the end I only want to know if this is a rabbit hole worth inspecting, or if I should further live with the insanely slow built-in COM Interop mechanism. ;-) Commented Nov 12 at 11:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.