Search code examples
c#.netcomcom-interopsolidworks

In C# COM projects, should I reference DLLs or TLBs? (Mainly SolidWorks)


I'm building a C# add-in for SolidWorks, and I can't seem to find any definitive answer as to which files to reference in my project. I've used .DLLs in previous projects, and .TLBs in this one. For SolidWorks specifically, I liked TLBs better because the definitions of functions are provided with their actual return types instead of just dynamic so that I don't have to look it up in SolidWorks' docs. However, in all the videos and sites I've found, nobody seems to be using TLBs. SolidWorks' docs site isn't so helpful as it's all over the place and explanations are very lackluster.

Docs for Early and Late Binding says that TLBs are just for early binding.

This page here says that TLBs are for C++/CLI, VB .NET, and VBA. No mention of C#. This one other page (can't find it right now) showed code using TLBs instead of DLLs, but everybody else seems to be using DLLs.

What am I actually supposed to use? What are the differences (for SolidWorks and for general COM stuff) other than early/late binding and dynamic?


Solution

  • When you are adding tlb, it get converted to the interop dlls behind the scenes so it is almost the same as adding dlls, but there is one major difference. Those interops would not have strong names so you might have troubles with compatibility in future, unlike the dll interops which are strong signed.

    I would also recommend to not use 'Embed Interop Types' option. In this case you will not have dynamics and can use I-versions of methods to access type safe versions of APIs.

    As a summary: add interop dlls (from .NET tab), set 'Embed Interop Types' option to False for all SOLIDWORKS interops