Search code examples
.netcomvisual-studio-2017registrygac

Visual Studio 2017: How to run an app that uses both 32 and 64-bit DLLs?


I am trying to run a web application built using Nodejs, Edgejs, Angular4, and a C# back-end services layer that is named "CatalogService.dll". I am using Visual Studio 2017 to build the C# service. Whenever I set the platform target in Visual Studio to "Any CPU" or "x64" and run the app, I get an error saying:

Retrieving the COM class factory for component with CLSID {EF5A2281-02BA-11D2-8922-AFB2FA76911F} failed due to the following error: 80040154 Class not registered

I looked up the CLSID "EF5A2281-02BA-11D2-8922-AFB2FA76911F" in the registry. The CLSID refers to a .dll file named RSEds.dll on my computer. The CLSID was under WOW6432Node, which tells me that RSEds.dll is 32-bit dll, but not 64-bit.

Since the DLL is 32-bit, I tried setting the target platform in Visual Studio to x86. But now when I run the app, I get a different error:

Error: Could not load file or assembly 'CatalogService.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

My computer is running Windows 7 x64. The C# project I am working on depends on both 32-bit and 64-bit DLLs. I have faced this issue for over 4 weeks now and have tried several other solutions:

  • Tried running Regsvr32 (both 32 and 64 bit versions) as an administrator to register the RSEds.dll. Even though the registration message said it was successful, this did not solve the issue.
  • Tried using RegAsm on the RSEds.dll, but this failed because RSEds.dll is not a .NET assembly.
  • Tried using gacutil /i to add the RSEds.dll to the Global Assembly Cache (GAC), but this resulted in the error: Failure adding assembly to the cache: The module was expected to contain an assembly manifest.
  • Tried changing the app pool settings in IIS to enable 32-bit applications, but this doesn't work because my web app doesn't use IIS.

How can I use the CatalogService.dll in my web app when it depends on both 32-bit and 64-bit dlls? I am certain that RSEds.dll is giving me issues because it is the only 32-bit .dll that my project uses. Is there a way I could register the RSEds.dll in the 64-bit registry even though it is 32-bit?


Solution

  • If there's no corresponding 64-bit DLL available, you have the option of hosting the CoClass inside a surrogate process. This way, your client can create an instance, even if the bitness of the server doesn't match. One drawback of this approach, however, is that calls across process boundaries are slower.

    See this answer for further details.