COM Error Using DLL Generated From TLB File

0

I am receiving this error when trying to use a DLL generated via tlbimpb.exe from a legacy TLB supplied by a 3rd party:

System.InvalidCastException: Unable to cast COM object of type 'SOME.CLASS' to interface type 'SOME.INTERFACE1'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{52525E8D-4359-4139-B454-F5157A3607D2}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Does anyone know if there's a proper way to use the "legacy" TLB in C# .NET 4.5+ beyond just making the DLL with tlbimp.exe? Or is it possible that the supplier of the TLB needs to do something on their end?

Further Details:

I have a DLL that is generated from a tlb file that a vendor has given me. I generated the DLL using tlbimp.exe. There is also a DLL that the vendor supplied, but they do not seem to remember how it was created. Regardless, both DLLs look to be identical when inspected with DotPeek/Reflector.

The DLL has 3 interfaces in it and one class. In order to use the methods in the DLL, I use the class such as follows:

VendorDLL.SomeClass vendorObject = new VendorDLL.SomeClass();
var string = vendorObject.Method1();

However, unless I install the vendor's SDK on a computer, I receive the COM error quoted up above when I try to instantiate an object from the class.

If I disassemble the DLL that is generated using Reflector/DotPeek, I can see that two of the interfaces uses the GUID mentioned n the error up above. The class and the other interface use different GUIDs. If I install the vendors software on a computer that it has never been on before, the vendor's installer doesn't register the 524 GUID that the error above is complaining about. Naturally, if I try to use any software that references the DLL, I get the above error. The only seeming work around is to install the vendor's SDK, as I mentioned up above.

I have raised this concern with the vendor and they are puzzled. They have pointed out that the test program that gets installed with their software uses the same COM object as the one I am trying to use, and it works without having the GUID I mentioned up above registered. This is true. I am able to use their test program without any COM errors. For what it is worth, their test program appears to have been written in VB6, so I am going to guess they are using the .TLB.

As a result, I am beginning to wonder if I am doing something incorrectly. I have looked at their code samples, but unfortunately all of their samples are written in VB (not sure which version), Delphi and an old version of Visual C++. All of the examples seem to be using the TLB file supplied by the vendor instead of a DLL. I have tried searching and all places seem to suggest that to use the TLB I have to generate a DLL in order to use it with C#. Is this correct or am I doing something wrong?

If I left something out, please let me know.

Edit: For those who are curious, I have tried using this in C# with the following project types:

  • Windows Forms
  • WPF
  • Console
  • WCF (via self hosting through console or Windows Forms).

All of them have [STAThread] on their main method.

c#
com
tlbimp
asked on Stack Overflow Nov 15, 2017 by Stephen • edited Nov 15, 2017 by Stephen

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0