[英]COMException while instantiating a form containing an ActiveX control in a WPF window
問題:在運行WPF應用程序時,我得到:
例外
PresentationFramework.dll中發生類型為'System.Windows.Markup.XamlParseException'的第一次機會異常
內部異常 :類未注冊
控制台中顯示的異常 :
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll
System.Runtime.InteropServices.COMException (0x80040154): Klasa niezarejestrowana. (Wyjatek od HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
w System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
w System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
w System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
w System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
w System.Windows.Forms.AxHost.CreateInstance()
w System.Windows.Forms.AxHost.GetOcxCreate()
w System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
w System.Windows.Forms.AxHost.CreateHandle()
w System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
w System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
w System.Windows.Forms.AxHost.EndInit()
w HomeSecurity.VideoStream.InitializeComponent() w c:\Users\R\Documents\Visual Studio 2013\Projects\HomeSecurity\HomeSecurity\VideoStream.Designer'HomeSecurity.vshost.exe' (CLR v4.0.30319: HomeSecurity.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Symbols loaded.
.cs:wiersz 48
w HomeSecurity.VideoStream..ctor() w c:\Users\R\Documents\Visual Studio 2013\Projects\HomeSecurity\HomeSecurity\VideoStream.cs:wiersz 13
w HomeSecurity.MainWindow..ctor() w c:\Users\R\Documents\Visual Studio 2013\Projects\HomeSecurity\HomeSecurity\MainWindow.xaml.cs:wiersz 23
The thread 0x1198 has exited with code 0 (0x0).
在WPF項目中,我有MainWindow
,默認情況下會自動生成XAML :
<Window x:Class="HomeSecurity.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid x:Name="Grid">
</Grid>
</Window>
在.cs文件中,我僅實例化了VideoStream
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
VideoStream VideoStream = new VideoStream();//THAT LINE PRODUCES THE EXCEPTION
}
}
VideoStream
是一個Form
。 此表單包含一個稱為AxisMediaControl Class
的ActiveX控件,看起來像這樣。 .cs文件中沒有其他代碼。
注意: WinForms
應用程序中相同的窗體不會導致任何問題。 從此窗體中刪除ActiveX控件將刪除異常(在WPF中)。
這些引用已添加:
內部異常 :
應當以32位編譯並運行該應用程序,以避免此特定錯誤。
也許太明顯了,但是您是否安裝了Axis SDK? 還是您已經注冊了必需的ActiveX DLL文件?
要在64位OS上構建32位應用程序,您必須注冊32位DLL文件(以管理員身份):
C:\\ Windows \\ SysWOW64 \\ regsvr32.exe“ \\ path \\ to \\ AxisSDKActiveX.dll” :: 32位ActiveX C:\\ Windows \\ regsvr32.exe“ \\ path \\ to \\ AxisSDKActiveX.dll” :: 64位ActiveX
注意SysWOW64文件夾。 它實際上包含32位工具和DLL文件。 了解這一點非常重要!
要查看當前注冊了哪些庫,請使用RegDllView application 。 您也可以在應用程序中使用F6鍵來注冊新庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.