.net 由于以下错误,检索具有 CLSID {XXXX} 的组件的 COM 类工厂失败:80040154
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1036856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154
提问by gopal
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 200864 bit version, I got this error:
我使用 C#.NET 开发了一个 Windows 服务来生成 PDF 报告。要生成 PDF 文件,我使用了第三方 dll。该应用程序在我的 Windows XP 平台上运行。当我在Windows Server 200864 位版本中部署该服务时,出现此错误:
Retrieving the COM class factory for component with CLSID {46521B1F-0A5B-4871-A4C2-FD5C9276F4C6} failed due to the following error: 80040154.
由于以下错误,检索具有 CLSID {46521B1F-0A5B-4871-A4C2-FD5C9276F4C6} 的组件的 COM 类工厂失败:80040154。
I registered the DLL using the regsvr32 command. I able to see this CLSID in the registry. But the problem persists.
我使用 regsvr32 命令注册了 DLL。我能够在注册表中看到这个 CLSID。但问题仍然存在。
What could be the problem?
可能是什么问题呢?
回答by Fabrice MARIANADIN
In VS - project properties - in the Build tab - platform target =X86
在 VS - 项目属性 - 在构建选项卡中 - 平台目标 =X86
回答by Daniel Ballinger
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.
我需要在 64 位机器上开发的 Web 应用程序中使用旧的 32 位 DLL。我使用该文件夹中的 regsrv32 版本将 32 位 DLL 注册到 windows\sysWOW64 文件夹中。
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.
对第三方 DLL 的调用在 Visual Studio 中通过单元测试工作,但在同一台机器上的 IIS 中托管的 Web 应用程序中失败,并出现 80040154 错误。
Changing the application pool to "Enable 32-Bit Applications" resolved the issue.
将应用程序池更改为“启用 32 位应用程序”解决了该问题。
回答by stevehipwell
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.
听起来您的服务是针对“任何 CPU”构建的,导致您在使用 COM 组件的 64 位上出错。您需要为x86.
The website is probably running as a 32-bit process which is why it can use the component. Building your solution against x86will force your service to run as 32-bit.
该网站可能作为 32 位进程运行,这就是它可以使用该组件的原因。构建您的解决方案x86将强制您的服务以 32 位运行。
回答by Joshua Starner
If you are looking for a way to make this work without recompiling your Any CPU application, here is another potential workaround:
如果您正在寻找一种无需重新编译 Any CPU 应用程序即可完成这项工作的方法,这里有另一种可能的解决方法:
- Locate your COM object GUID under the HKey_Classes_Root\Wow6432Node\CLSID\{GUID}
- 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
- Add a new key under HKey_Classes_Root\Wow6432Node\AppID. The new key should be called the same as the COM object GUID.
- Under the new key you just added, add a new String Value, and call it DllSurrogate. Leave the value empty.
- 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.
- 在 HKey_Classes_Root\Wow6432Node\CLSID\{GUID} 下找到您的 COM 对象 GUID
- 一旦找到,添加一个新的 REG_SZ(字符串)值。名称应为 AppID,数据应为您刚刚搜索的相同 COM 对象 GUID
- 在 HKey_Classes_Root\Wow6432Node\AppID 下添加一个新项。新键的名称应与 COM 对象 GUID 的名称相同。
- 在您刚刚添加的新键下,添加一个新的字符串值,并将其命名为 DllSurrogate。将该值留空。
- 在 HKey_Local_Machine\Software\Classes\AppID\ 下创建一个新密钥,新密钥的名称应与 COM 对象的 GUID 相同。无需在此键下添加任何值。
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/
来源:https: //techtalk.gfi.com/32bit-object-64bit-environment/
回答by nazim hatipoglu
You dont have to configure your project properties platform target X86. You can also configure the iis options to work with x86 like that
您不必配置您的项目属性平台目标 X86。您还可以将 iis 选项配置为这样使用 x86
- Select Application pool
- Select the pool which your app uses
- Advanced settings
- Enable 32 bit applications true
- 选择应用程序池
- 选择您的应用使用的池
- 高级设置
- 启用 32 位应用程序true
回答by sharptooth
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.
问题是服务器进程是 64 位,库是 32 位,它试图在同一个进程(进程内服务器)中创建 COM 组件。要么重新编译服务器并使其成为 32 位,要么保持服务器不变并使 COM 组件处于进程外。使 COM 服务器脱离进程的最简单方法是创建一个 COM+ 应用程序 - 控制面板 -> 管理工具 -> ComponentServices。
回答by Eduardo Xavier
I didn't change any compile settings.
我没有更改任何编译设置。
Just set "Enable 32-bit Application = True" in AppPool Advanced Settings.
只需在 AppPool 高级设置中设置“启用 32 位应用程序 = True”。
It worked for me
它对我有用
回答by Juan
The solution for windows 2008 server x64 is:
windows 2008 server x64 的解决方案是:
- open cmd.exe with Administrator permission.
- Copy the dll to the folder C:\Windows\SysWOW64
- run regsvr32 from C:\Windows\SysWOW64
- Verify that dll is in registry of Windows.
- If you has a .exe x86 that use the dll, the exe must be compiled in x86 mode.
- The exe must be installed in folder C:\Program Files (x86)
- 以管理员权限打开 cmd.exe。
- 将dll复制到文件夹C:\Windows\SysWOW64
- 从 C:\Windows\SysWOW64 运行 regsvr32
- 验证 dll 是否在 Windows 的注册表中。
- 如果您有使用 dll 的 .exe x86,则必须在 x86 模式下编译该 exe。
- exe 必须安装在文件夹 C:\Program Files (x86) 中
This procedure is valid, it is ok.
这个程序是有效的,没问题。
回答by Gerhard Powell
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.
从注册表中删除 64 位。
- c:\windows\system32\regsvr32.exe /U
- This will not remove references to other copied of the dll in other folders.
- c:\windows\system32\regsvr32.exe /U
- 这不会删除对其他文件夹中其他 dll 副本的引用。
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.
- 找到名为 HKEY_CLASSES_ROOT\CLSID{......}\InprocServer32 的键。该键将 DLL 的文件名作为其默认值。
- 我删除了 HKEY_CLASSES_ROOT\CLSID{......} 文件夹。
Register it as 32bit:
将其注册为 32 位:
C:\Windows\SysWOW64\regsvr32 <file.dll>
C:\Windows\SysWOW64\regsvr32 <file.dll>
Registering it as 32bit without removing the 64bit registration does not resolve my issue.
将其注册为 32 位而不删除 64 位注册并不能解决我的问题。
回答by jinushaun
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.
我有一个使用 64 位 DLL 的 Windows 服务项目设置为“Any-CPU”。同样的错误信息。尝试了一大堆东西,但没有任何效果。最后,我进入项目 Properties -> Build 并注意到项目已选中“Prefer 32-bit”。取消选中此项,不再有错误。
My guess is that the windows service was expecting a 32-bit DLL, and couldn't find it.
我的猜测是 Windows 服务需要 32 位 DLL,但找不到它。

