C# 如何解决未注册的 COM 异常类(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG))?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1496214/
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
How to solve COM Exception Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))?
提问by Jaswant Agarwal
When I try to create a instance of a COM class it throws an exception as
当我尝试创建 COM 类的实例时,它会抛出异常
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
类未注册(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG))
Please suggest how could i solve it?
请建议我如何解决它?
采纳答案by Jay Riggs
It looks like whichever program or process you're trying to initialize either isn't installed on your machine, has a damaged installation or needs to be registered.
看起来您尝试初始化的任何程序或进程都没有安装在您的机器上,安装已损坏或需要注册。
Either install it, repair it (via Add/Remove Programs) or register it (via Regsvr32.exe).
安装、修复(通过添加/删除程序)或注册(通过 Regsvr32.exe)。
You haven't provided enough information for us to help you any more than this.
您没有提供足够的信息让我们为您提供更多帮助。
回答by Alex Martelli
回答by Andrew Keith
Also note that the class context when initializing can create that exception. If you have an object which is coded as INPROC_SERVER but you try to CoCreateInstance as CLSCTX_LOCAL_SERVER, you will also get that error.
另请注意,初始化时的类上下文可以创建该异常。如果您有一个编码为 INPROC_SERVER 的对象,但您尝试将 CoCreateInstance 编码为 CLSCTX_LOCAL_SERVER,您也会收到该错误。
You need to ensure the object is registered and the CoCreateInstance is creating an instance with the correct class context.
您需要确保对象已注册,并且 CoCreateInstance 正在使用正确的类上下文创建实例。
回答by Andy Fiedler
You need to make sure all of your assemblies are compiling for the correct architecture. Try changing the architecture for x86 if reinstalling the COM component doesn't work.
您需要确保所有程序集都针对正确的体系结构进行编译。如果重新安装 COM 组件不起作用,请尝试更改 x86 的体系结构。
回答by Matsen75
If you are using 64-bit COM components in a web application on IIS, make sure the application pool is set to not allow 32 bit applications (Enable 32-Bit Applications: falsein advanced settings)
如果您在 IIS 上的 Web 应用程序中使用 64 位 COM 组件,请确保将应用程序池设置为不允许 32 位应用程序(启用 32 位应用程序:高级设置中的false)
回答by Waheed
My problem and the solution
我的问题和解决方案
I have a 32 bit third party dll which i have installed in 2008 R2 machine which is 64 bit.
我有一个 32 位的第三方 dll,我已将其安装在 64 位的 2008 R2 机器上。
I have a wcf service created in .net 4.5 framework which calls the 32 bit third party dll for process. Now i have build property set to target 'any' cpu and deployed it to the 64 bit machine.
我有一个在 .net 4.5 框架中创建的 wcf 服务,它调用 32 位第三方 dll 进行处理。现在我已将构建属性设置为针对“任何”cpu 并将其部署到 64 位机器。
when i tried to invoke the wcf service got error "80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG"
当我尝试调用 wcf 服务时出现错误“80040154 类未注册(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG”)
Now i used ProcMon.exe to trace the com registry issue and identified that the process is looking for the registry entry at HKLM\CLSID and HKCR\CLSID where there is no entry.
现在我使用 ProcMon.exe 来跟踪 com 注册表问题,并确定该进程正在寻找 HKLM\CLSID 和 HKCR\CLSID 中没有条目的注册表项。
Came to know that Microsoft will not register the 32 bit com components to the paths HKLM\CLSID, HKCR\CLSID in 64 bit machine rather it places the entry in HKLM\Wow6432Node\CLSID and HKCR\Wow6432Node\CLSID paths.
了解到 Microsoft 不会将 32 位 com 组件注册到 64 位机器中的 HKLM\CLSID、HKCR\CLSID 路径,而是将条目放在 HKLM\Wow6432Node\CLSID 和 HKCR\Wow6432Node\CLSID 路径中。
Now the conflict is 64 bit process trying to invoke 32 bit process in 64 bit machine which will look for the registry entry in HKLM\CLSID, HKCR\CLSID. The solution is we have to force the 64 bit process to look at the registry entry at HKLM\Wow6432Node\CLSID and HKCR\Wow6432Node\CLSID.
现在冲突是 64 位进程试图调用 64 位机器中的 32 位进程,它将在 HKLM\CLSID、HKCR\CLSID 中查找注册表项。解决方案是我们必须强制 64 位进程查看 HKLM\Wow6432Node\CLSID 和 HKCR\Wow6432Node\CLSID 处的注册表项。
This can be achieved by configuring the wcf service project properties to target to 'X86' machine instead of 'Any'.
这可以通过将 wcf 服务项目属性配置为定位到“X86”机器而不是“Any”来实现。
After deploying the 'X86' version to the 2008 R2 server got the issue "System.BadImageFormatException: Could not load file or assembly"
将“X86”版本部署到 2008 R2 服务器后出现问题“System.BadImageFormatException:无法加载文件或程序集”
Solution to this badimageformatexception is setting the 'Enable32bitApplications' to 'True' in IIS Apppool properties for the right apppool.
此 badimageformatexception 的解决方案是将 IIS Apppool 属性中的“Enable32bitApplications”设置为“True”以获取正确的应用程序池。
回答by Yoky
I got it to work by Enabling 32 bit applications in the Application Pool advanced settings. Right click on the application pool and choose advanced settings - enable 32 bit applications. This may help someone out there.
我通过在应用程序池高级设置中启用 32 位应用程序使其工作。右键单击应用程序池并选择高级设置 - 启用 32 位应用程序。这可能会帮助那里的人。
回答by jbooker
For me, I had to create 64 bit build configuration.
对我来说,我必须创建 64 位构建配置。
回答by Basheer AL-MOMANI
in my case
就我而言
my platform
is x64
my platform
是 x64
the Dll library(sdk)
and the redistributable package
is x64
the Dll library(sdk)
这redistributable package
是 x64
so
所以
in the solution explorer
navigate to your project
open
Properties
change the Platform target from AnyCPU to x64
在解决方案资源管理器中
navigate to your project
打开
Properties
change the Platform target from AnyCPU to x64
回答by Martín Martínez
Here find the solution, run mmc -32 tool (not dcomcfg)
在这里找到解决方案,运行 mmc -32 工具(不是 dcomcfg)
On 64 bit system with 32 bit Office try this:
在 32 位 Office 的 64 位系统上试试这个:
Start
Run
mmc -32
File
Add Remove Snap-in
Component Services
Add
OK
Console Root
Component Services
Computers
My Computer
DCOM Config
Microsoft Excel Application