Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154 – Dev

The best answers to the question “Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154” in the category Dev.

QUESTION:

I developed a Windows service using C#.NET to generate PDF report. To generate PDF file I am using a third party dll. The application is running in my Windows XP platform. When I deployed the service in Windows Server 2008 64 bit version, I got this error:

Retrieving the COM class factory for
component with CLSID
{46521B1F-0A5B-4871-A4C2-FD5C9276F4C6}
failed due to the following error:
80040154.

I registered the DLL using the regsvr32 command. I able to see this CLSID in the registry. But the problem persists.

What could be the problem?

ANSWER:

I ran into a very similar issue.

I needed to use an old 32-bit DLL within a Web Application that was being developed on a 64-bit machine. I registered the 32-bit DLL into the windows\sysWOW64 folder using the version of regsrv32 in that folder.

Calls to the third party DLL worked from unit tests in Visual Studio but failed from the Web Application hosted in IIS on the same machine with the 80040154 error.

Changing the application pool to “Enable 32-Bit Applications” resolved the issue.

ANSWER:

In VS – project properties – in the Build tab – platform target =X86

ANSWER:

You dont have to configure your project properties platform target X86.
You can also configure the iis options to work with x86 like that

  • Select Application pool
  • Select the pool which your app uses
  • Advanced settings
  • Enable 32 bit applications true

ANSWER:

It sounds like your service was built against ‘Any CPU’, causing you errors on 64-bit where you are using COM components. You need to build it for x86.

The website is probably running as a 32-bit process which is why it can use the component. Building your solution against x86 will force your service to run as 32-bit.