C# 在WPF窗口中实例化包含ActiveX控件的窗体时发生COMException
问题:运行WPF应用程序时,我得到: 例外情况 类型的第一次机会例外 中出现“System.Windows.Markup.XamlParseException” PresentationFramework.dll 内部异常:类未注册 控制台中打印的异常:C# 在WPF窗口中实例化包含ActiveX控件的窗体时发生COMException,c#,wpf,winforms,xaml,activex,C#,Wpf,Winforms,Xaml,Activex,问题:运行WPF应用程序时,我得到: 例外情况 类型的第一次机会例外 中出现“System.Windows.Markup.XamlParseException” PresentationFramework.dll 内部异常:类未注册 控制台中打印的异常: A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll A fi
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项目中,我有一个自动生成默认值的main窗口
:
视频流
是一种形式
。此表单包含一个名为AxisMediaControl类的ActiveX控件,看起来是这样的。.cs文件中没有其他代码
注意:WinForms
应用程序中的相同表单不会导致任何问题。从此窗体中删除ActiveX控件将删除异常(在WPF中)
添加这些引用:
内部异常:
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).
人们应该以32位的方式编译和运行应用程序,以避免出现这种特殊错误。也许这太明显了,但是您是否安装了Axis SDK?或者您是否已注册所需的ActiveX DLL文件 要在64位操作系统上构建32位应用程序,必须注册32位DLL文件(作为管理员): C:\Windows\SysWOW64\regsvr32.exe“\path\to\axisdkactivex.dll”::32位ActiveX C:\Windows\regsvr32.exe“\path\to\axisdkactivex.dll”::64位ActiveX 请注意SysWOW64文件夹。它实际上包含32位工具和DLL文件了解这一点非常重要强>
要查看当前注册的库,请使用。您也可以使用应用程序中的F6键注册一个新库。检查内部异常。@RohitVats感谢您抽出时间。我在底部添加了内部异常。请刷新一些COM异常,与WPF无关。对不起,我不知道(COMException的ErrorCode值是多少?您的winforms应用程序是否在WPF应用程序失败的同一台计算机上成功运行?如果是,可能是64/32位兼容性问题..您的WPF应用程序是否为64位?winforms应用程序如何?
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
VideoStream VideoStream = new VideoStream();//THAT LINE PRODUCES THE EXCEPTION
}
}