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

StackOverflow https://stackoverflow.com/questions/1036856

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

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

If you are looking for a way to make this work without recompiling your Any CPU application, here is another potential workaround:

  1. Locate your COM object GUID under the HKey_Classes_Root\Wow6432Node\CLSID\{GUID}
  2. Once located add a new REG_SZ (string) Value. Name should be AppID and data should be the same COM object GUID you have just searched for
  3. Add a new key under HKey_Classes_Root\Wow6432Node\AppID. The new key should be called the same as the COM object GUID.
  4. Under the new key you just added, add a new String Value, and call it DllSurrogate. Leave the value empty.
  5. Create a new Key under HKey_Local_Machine\Software\Classes\AppID\ Again the new key should be called the same as the COM object’s GUID. No values are necessary to be added under this key.

I take no credit for the solution, but it worked for us. Check the source link for more information and other comments.

Source: https://techtalk.gfi.com/32bit-object-64bit-environment/

The problem is that the server process is 64 bit and the library is 32-bit and it tries to create the COM component in the same process (in-proc server). Either you recompile the server and make it 32-bit or you leave the server unchanged and make the COM component out-of-process. The easiest way to make a COM server out-of-process is to create a COM+ application - Control Panel -> Administrative Tools -> ComponentServices.

I didn't change any compile settings.

Just set "Enable 32-bit Application = True" in AppPool Advanced Settings.

It worked for me

The solution for windows 2008 server x64 is:

  1. open cmd.exe with Administrator permission.
  2. Copy the dll to the folder C:\Windows\SysWOW64
  3. run regsvr32 from C:\Windows\SysWOW64
  4. Verify that dll is in registry of Windows.
  5. If you has a .exe x86 that use the dll, the exe must be compiled in x86 mode.
  6. The exe must be installed in folder C:\Program Files (x86)

This procedure is valid, it is ok.

Had a related issue with a different, but similar fix:

I had a Windows service project set to "Any-CPU" using a 64-bit DLL. Same error message. Tried a whole bunch of things, but nothing worked. Finally, I went into project Properties -> Build and noticed that project had "Prefer 32-bit" checked. Unchecked this and no more error.

My guess is that the windows service was expecting a 32-bit DLL, and couldn't find it.

I had the same issue, but the other answers only supplied one part of the solution.

The solution is two fold:

Remove the 64bit from the Registery.

  • c:\windows\system32\regsvr32.exe /U
  • This will not remove references to other copied of the dll in other folders.

or

  • Find the key called HKEY_CLASSES_ROOT\CLSID{......}\InprocServer32. This key will have the filename of the DLL as its default value.
  • I removed the HKEY_CLASSES_ROOT\CLSID{......} folder.

Register it as 32bit:

  • C:\Windows\SysWOW64\regsvr32 <file.dll>

Registering it as 32bit without removing the 64bit registration does not resolve my issue.

To change to x86:

  1. Create a setup project for your solution.
  2. After you create it, Go to Solution Explorer, right click the setup project.
    • Press Configuration Manager.
    • Click on: "Active Solution Platform" combobox and select New (If there is no x86 displayed)
    • Select from first combo x86 then press OK.
    • rebuild Setup project, then rebuild All the project.

If you are running a website, you could also try to set your application pool to disable 32-bit Applications (under advanced settings of a pool).

For anyone using VSTO, the problem for me was a missing reference to the office assembly. It would also appear if you were trying to instantiate certain VSTO objects manually.

In my personal case the issue was fixed searching for the class id in the Windows's Registry on developer machine (because the issue was thrown in a client PC). This action will be placed into the COM component that causes the issue: an x86 library referenced in my .NET project that was not being registered as OCX/COM for the installer or updater application.

Regards

My problem was that I had the wrong MS Sync FrameWork version (1.0) in my project References. After update to the version 2.1, the error was gone and life is good again.

I found that my problem related to the actual registration of the DLL.

First run "Regedit.exe" from a CMD prompt (I raised it's security level to Administrator, "just in case") then search the Registry (by clicking on "Edit/Find" in the RegEdit menu or by pressing Ctrl+F) for the CLSID showing in the error message which you received regarding the COM class factory. My CLSID was 29AB7A12-B531-450E-8F7A-EA94C2F3C05F. When this key is found, select the sub-key "InProcServer2" under that Hive node and ascertain the filename of the problem DLL in the right hand Regedit frame. showing under "Default" . If that file resides in "C:\Windows\SysWow64"(such as C:\Windows\SysWow64\Redemption.dll") then it is important that you use the "C:\Windows\SysWow64\RegSvr32.exe" file to register that DLL from the command line and NOT the default "C:\Windows\System32\RegSvr32.exe" file. So I ran a CMD prompt (under Administrative level control (just in case this level is need required) and type on the command line (in the case of my DLL): C:\Windows\SysWow64\RegSvr32.exe c:\Windows\SysWow64\Redemption.dll the press enter. Close the command window (via "Exit" then Restart your computer (always use restart instead of Close Down then start up, since (strangely) Restart perform a thorough shut down and reload of everything whereas "Shut Down" and Power-Up reloads a stored cache of drivers and other values (which may be faulty). Whenever you register a DLL in the future, remember to use the SysWow64 "RegSvr32.exe" for any DLL stored in the C:\Windows\SysWow64 folder and this problem c(if it is caused by incorrect registration) should not happen again.

In my case, I'm producing ms office file like word or excel, I run Win+R and execute dcomcnfg, in the DCOM Config, besides select OFFICE related name item (such as name contains Excel or Word or Office) and Open the properties, select Identity tab and select the interactive user. as this answer,

My error message show CLSID {000209FF-0000-0000-C000-000000000046}, so I have to try to find this specific CLSID in DCOM Config, and it does exsits, and I select it and follow same step set the interactive user, then it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top