我有一个VB.NET项目,它在我的开发机器上工作正常(自然:-)),但在我测试的两台不同的计算机上,当我尝试打开一个特定的时,我得到以下错误形成。所有三台计算机(包括我的开发机器,都可以使用)是Windows 7 64位机器,两个专业版(包括我的),第三台是Home Basic。
我怀疑它与我插入的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)
答案 0 :(得分:1)
汉斯说,之所以会发生这种情况,是因为您使用的程序(WMP,Flash)可能未安装在目标计算机上。您可以做的最简单的事情就是尝试检测这一点并警告用户他们需要安装这些程序以实现全部功能。所以像这样:
Try
Dim test as New WindowMediaPlayerControl
Catch ex as exception
MsgBox("The program requires Media Player to be installed.")
End Try
然后你甚至可以设置一个标志,以便你可以避免加载带有控件的窗口,以避免用户看到错误。
我不确定这是否可行,但如果您使用ClickOnce部署,可以在此处查看是否可以向您的程序添加自定义所需的安装程序。 http://msdn.microsoft.com/en-us/library/ms165429(VS.80).aspx
编辑:正如汉斯指出的那样,我的Try Catch上面有点懒惰,如果你试图处理一个特定的错误,你应该总是尝试非常具体。对于这种情况,这样的事情。
Catch ex As System.Runtime.InteropServices.COMException When ex.Message.Contains("REGDB_E_CLASSNOTREG")