4

I'm trying to use a 3rd party COM DLL (I don't believe its a .NET component) from a .NET service without registering the COM DLL but I'm having no luck so far.

I've copied the manifest files from here (http://stackoverflow.com/questions/465882/generate-manifest-files-for-registration-free-com) to use as a starting point (I generated the COM DLL manifest using the referenced mt.exe/regsvr42.exe). However all I get is the following error:

Exception: System.InvalidCastException Message: Unable to cast COM object of type 'LOGICLib.LogicClass' to interface type 'LOGICLib.ILogic'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAA3E8FB4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). Source: Interop.LOGICLib at LOGICLib.LogicSecuredClass.Connect(String IP, UInt16 Value, Int32& Result) at My.Server.MyAssembly.Loader.Connect() in D:\MyProject\Source\Server\MyAssembly\Loader.cs:line 461

The application manifest is named after the exe that starts the service - I've also tried naming it after the assembly that calls the COM DLL. I've tried starting on the command line and via Visual Studio's debugger. I've also tried using the Interop file supplied by the third party and generating my own.

(Note - I've only tested under Windows XP so far.)

I've spent two days on this now and have not progressed at all. Any ideas what I may have missed?

cheesemp
  • 307
  • 1
  • 3
  • 10

2 Answers2

4

The application manifest is named after the exe that starts the service

Yes, this does not work. Windows always looks for a manifest in the EXE itself, embedded as an unmanaged resource. Only when it cannot find one in there will it look for a .manifest file on disk. Problem is, a managed program built with VS2008 and up already has a manifest. The default one says "I'm Vista aware" only.

You can verify this for yourself by using File + Open + File and selecting your EXE. Open the RT_MANIFEST node and double-click resource 1. If you don't see your reg-free COM manifest entries there then it isn't going to work.

To fix, use Project + Add New Item and select the Application Manifest File item template. You'll get the boilerplate manifest, copy and paste your regfree COM entries in there.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • This is very interesting a could well be the answer as there is an embedded manifest (surprising the file doesn't override it?). I'm just trying adding some entries now. Do I have include the file and comInterfaceExternalProxyStub entries from the mt.exe generated manifest or just the dependent assembly? – cheesemp Jan 20 '11 at 10:22
  • It now appears worse I get the following error: Exception: System.Runtime.InteropServices.COMException Message: Retrieving the COM class factory for component with CLSID {AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAA077} failed due to the following error: 80040154. – cheesemp Jan 20 '11 at 10:57
  • 1
    I've got it working so I marking this answer as the accepted. For the record I had to do the following: 1) Created an embedded manifest as described above with the dependent assembly entry from step 2, 2) Generate the two manifests using regsvr42 (from code project) not mt.exe version. The app one i then copied into embedded manifest. 3) Run exe outside of Visual studio - guess it never reads manifest if run via debugger. I think I could have used mt.exe manifest with a bit more work but as its working and taken me 3 and half days I'm not touching it further. – cheesemp Jan 21 '11 at 11:14
  • 1
    Just a quick note, you can use the reg-free COM within the Visual Studio debugger, if you uncheck the "Enable the Visual Studio hosting process" checkbox from the "Debug" settings menu. – BTownTKD Sep 26 '12 at 13:52
-1

Well, from the exception, you're getting a cast error when trying to cast an object of type LogicClass to an interface type of ILogic. Looks like LogicClass doesn't implement ILogic.

You didn't supply what the DLL is or where you got it, so you're best bet is to look at the documentation for the library you're trying to use. Just a wild guess, but it looks like you're implementing it incorrectly.

Bob G
  • 1,226
  • 2
  • 16
  • 24
  • It works fine if I register the COM DLL using regsvr32. It only stops working when I unregister it. Regarding the DLLs origin it was produced to talk to a remote storage server by the storage server company. – cheesemp Jan 19 '11 at 14:07