0

How do I access COM objects from Node.

I have already tried an implementation using Edge and a simple DLL using C#. When I call the invoke function everything works as expected in the DLL, but the DLL cannot find the COM object specified. Yet, if I build a test program in the same VS Solution, and run it from there it works just fine.

So here is my code (that's the first actual use of the COM object in my code, before that is just types):

using QBXMLRP2Lib;
...
try { rp = new RequestProcessor2(); } catch (Exception e) { return e }

And it returns this error:

{ Error: Retrieving the COM class factory for component with CLSID {45F5708E-3B43-4FA8-BE7E-A5F1849214CB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    at Error (native)
  ErrorCode: -2147221164,
  Message: 'Retrieving the COM class factory for component with CLSID {45F5708E-3B43-4FA8-BE7E-A5F1849214CB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).',
  Data: {},
  InnerException: null,
  TargetSite: {},
  StackTrace: 
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Startup.DoQBQuery(Object options) in c:\path\to\my\source\code\Startup.cs:line 35
  HelpLink: null,
  Source: 'mscorlib',
  HResult: -2147221164,
  message: 'Retrieving the COM class factory for component with CLSID {45F5708E-3B43-4FA8-BE7E-A5F1849214CB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).',
  name: 'System.Runtime.InteropServices.COMException' }
Arlen Beiler
  • 12,691
  • 32
  • 81
  • 132
  • It's a registration issue. Have you registered the COM object with regasm/codebase? It could also be due to a x86/x64 mismatch. – Simon Mourier May 16 '17 at 16:26
  • Hah, that was the problem. I was using 64-bit node and the QB XML library is 32 bit. Care to put that in an answer? – Arlen Beiler May 16 '17 at 17:04

1 Answers1

0

0x80040154 or REGDB_E_CLASSNOTREG "Class not registered" error is a very common error indicating a COM object registration issue. COM basically tells you it cannot find the object you're looking for.

In todays world, it's, most of the time, a x86/x64 mismatch: the client and the server (when it's an in-process DLL) are not compiled with the same bitness.

If using .NET as the .DLL (in-process server), you also want to make sure you've registered it using RegAsm /codebase, at least during dev/test phases.

Community
  • 1
  • 1
Simon Mourier
  • 117,251
  • 17
  • 221
  • 269