vb.net 如何修复此 COMException -“类未注册(来自 HRESULT 的异常:0x80040154”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13703350/
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 fix this COMException - "Class not registered (Exception from HRESULT: 0x80040154"
提问by Chiwda
I have a VB.NETproject, and it works fine on my deveelopment machine (naturally :-)), but on two different computers I tested on, I get the following error, when I attempt to open a specific form. All three computers (including my dev machine, which works) are Windows 7 64-bit machines, two Professional Edition (including mine) and the third is Home Basic.
我有一个VB.NET项目,它在我的开发机器上运行良好(自然是 :-)),但是在我测试的两台不同的计算机上,当我尝试打开特定表单时出现以下错误。所有三台计算机(包括我的开发机,可以工作)都是 Windows 7 64 位机器,两台专业版(包括我的),第三台是家庭基本版。
My suspicion is that it has something to do with Windows Media Playeror Adobe SWF player controls I have inserted. Here is the error:
我怀疑它与我插入的Windows Media Player或 Adobe SWF 播放器控件有关。这是错误:
System.Runtime.InteropServices.COMException (0x80040154): Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance()
at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at WizoDesktop.FormPlayer.c4cf84dbbc00986a0b43ce266bdec20d7()
at WizoDesktop.FormPlayer..ctor()
at A.c237671a6e3a2745adc05bbdc0150506d.cff280b017b22ca351191a6adb2feeae4()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
回答by Kratz
Like Hans says, it occurs because the programs you are using (WMP, Flash) are likely not installed on the target machine. The easiest thing you could do is simply try to detect this and warn the user that they need to install those programs for full functionality. So something like this:
正如 Hans 所说,这是因为您正在使用的程序(WMP、Flash)可能没有安装在目标机器上。您可以做的最简单的事情就是尝试检测这一点并警告用户他们需要安装这些程序才能获得完整功能。所以像这样:
Try
Dim test as New WindowMediaPlayerControl
Catch ex as exception
MsgBox("The program requires Media Player to be installed.")
End Try
Then you could even set a flag that so that you can avoid loading the windows with the control on it, to avoid the user seeing the error.
然后你甚至可以设置一个标志,这样你就可以避免加载带有控件的窗口,以避免用户看到错误。
I'm not sure if this is possible, but if you are using ClickOnce deployment you can look here for the possibility of adding custom required installers to your program. http://msdn.microsoft.com/en-us/library/ms165429(VS.80).aspx
我不确定这是否可行,但如果您使用 ClickOnce 部署,您可以在此处查看将自定义所需安装程序添加到您的程序的可能性。http://msdn.microsoft.com/en-us/library/ms165429(VS.80).aspx
Edit: As Hans pointed out, my Try Catch is a little lazy above, you should always try to be very specific if you are trying to handle a particular error. Something like this for this case.
编辑:正如 Hans 指出的,我的 Try Catch 上面有点懒惰,如果您尝试处理特定错误,您应该始终尝试非常具体。对于这种情况,类似这样的事情。
Catch ex As System.Runtime.InteropServices.COMException When ex.Message.Contains("REGDB_E_CLASSNOTREG")

