.net 如何修复 COMException 错误 80040154?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7197506/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:51:00  来源:igfitidea点击:

How to repair COMException error 80040154?

.netexceptioncomdllregistration

提问by Hymannad

Moving a working C# project from a 64-bit Windows 7 machine to a 32-bit XP machine caused the following error:

将工作 C# 项目从 64 位 Windows 7 机器移动到 32 位 XP 机器导致以下错误:

Retrieving the COM class factory for component with CLSID {681EF637-F129-4AE9-94BB-618937E3F6B6} failed due to the following error: 80040154.

Retrieving the COM class factory for component with CLSID {681EF637-F129-4AE9-94BB-618937E3F6B6} failed due to the following error: 80040154.

681EF637-F129-4AE9-94BB-618937E3F6B6is not in the registry so it is not properly installed, but this is same ID that was previously a problem on the 64-bit Windows 7 machine.

681EF637-F129-4AE9-94BB-618937E3F6B6不在注册表中,因此未正确安装,但这与以前在 64 位 Windows 7 计算机上出现问题的 ID 相同。

The solution to this error on the 64-bit Windows 7 machine was found here(change Platform Target to x86) but this does not solve the problem on the 32-bit XP machine.

解决这个错误的64位Windows 7的计算机上发现这里(其他城市平台目标x86的),但是这并没有解决32位XP机器上的问题。

How do I find the DLL associated with 681EF637-F129-4AE9-94BB-618937E3F6B6, or, even better, how do I repair this exception?

如何找到与 关联的 DLL 681EF637-F129-4AE9-94BB-618937E3F6B6,或者更好的是,如何修复此异常?

采纳答案by Ciaran Keating

To find the DLL, go to your 64-bit machine and open the registry. Find the key called HKEY_CLASSES_ROOT\CLSID\{681EF637-F129-4AE9-94BB-618937E3F6B6}\InprocServer32. This key will have the filename of the DLL as its default value.

要找到 DLL,请转到您的 64 位计算机并打开注册表。找到名为 的键HKEY_CLASSES_ROOT\CLSID\{681EF637-F129-4AE9-94BB-618937E3F6B6}\InprocServer32。该键将 DLL 的文件名作为其默认值。

If you solved the problem on your 64-bit machine by recompiling your project for x86, then you'll need to look in the 32-bit portion of the registry instead of in the normal place. This is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\CLSID\{681EF637-F129-4AE9-94BB-618937E3F6B6}\InprocServer32.

如果您通过为 x86 重新编译项目来解决 64 位机器上的问题,那么您需要查看注册表的 32 位部分而不是正常位置。这是HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\CLSID\{681EF637-F129-4AE9-94BB-618937E3F6B6}\InprocServer32

If the DLL is built for 32 bits then you can use it directly on your 32-bit machine. If it's built for 64 bits then you'll have to contact the vendor and get a 32-bit version from them.

如果 DLL 是为 32 位构建的,那么您可以直接在 32 位机器上使用它。如果它是为 64 位构建的,那么您必须联系供应商并从他们那里获得 32 位版本。

When you have the DLL, register it by running c:\windows\system32\regsvr32.exe.

拥有 DLL 后,通过运行 c:\windows\system32\regsvr32.exe 来注册它。

回答by Preben Huybrechts

I had the same issue in a Windows Service. All keys where in the right place in the registry. The build of the service was done for x86 and I still got the exception. I found out about CorFlags.exe

我在 Windows 服务中遇到了同样的问题。所有键都在注册表中的正确位置。该服务的构建是针对 x86 完成的,但我仍然遇到异常。我发现了CorFlags.exe

Run this on your service.exewithout flags to verify if you run under 32 bit. If not run it with the flag /32BIT+ /Force(Force only for signed assemblies)

service.exe没有标志的情况下运行它以验证您是否在 32 位下运行。如果不使用标志运行它/32BIT+ /Force(仅对签名程序集强制执行)

If you have UAC turned you can get the following error: corflags : error CF001 : Could not open file for writingGive the user full control on the assemblies.

如果您打开了 UAC,您可能会收到以下错误:corflags : error CF001 : Could not open file for writing让用户完全控制程序集。

Console output

控制台输出

回答by kalidoss

WORKAROUND:

解决方法:

The possible workaround is modify your project's platform from 'Any CPU' to 'X86' (in Project's Properties, Build/Platform's Target)

可能的解决方法是将您的项目平台从“任何 CPU”修改为“X86”(在项目的属性、构建/平台的目标中)

ROOTCAUSE

根本原因

The VSS Interop is a managed assembly using 32-bit Framework and the dll contains a 32-bit COM object. If you run this COM dll in 64 bit environment, you will get the error message.

VSS Interop 是一个使用 32 位框架的托管程序集,dll 包含一个 32 位 COM 对象。如果您在 64 位环境中运行此 COM dll,您将收到错误消息。

回答by Yogesh

Move excel variables which are global declare in your form to local like in my form I have:

将表单中全局声明的 excel 变量移动到本地,就像在我的表单中一样:

Dim xls As New MyExcel.Interop.Application  
Dim xlb As MyExcel.Interop.Workbook

above two lines were declare global in my form so i moved these two lines to local function and now tool is working fine.

以上两行在我的表单中被声明为全局,所以我将这两行移动到本地函数,现在工具工作正常。