在WPF窗口中实例化包含ActiveX控件的窗体时出现COMException

时间:2014-01-03 18:21:05

标签: c# wpf winforms xaml activex

问题:在运行WPF应用程序时,我得到:

异常

  

类型的第一次机会异常   'System.Windows.Markup.XamlParseException'发生在   PresentationFramework.dll

内部异常:未注册的类

Enter image description here

http://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k(EHCOM);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.0)&rd=true

在控制台中打印的例外

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
        }
    }

VideoStreamForm。此表单包含一个名为AxisMediaControl Class的ActiveX控件,它看起来就像这样。 .cs文件中没有其他代码。

注意:WinForms应用程序中的相同表单不会导致任何问题。从此表单中删除ActiveX控件会删除异常(在WPF中)。

Enter image description here


添加了以下参考资料:

Enter image description here

Enter image description here


内部异常

Enter image description here  http://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k(EHCOM);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.0)&rd=true

2 个答案:

答案 0 :(得分:0)

应该编译并运行32位应用程序以避免此特定错误。

答案 1 :(得分:0)

也许它太明显了,但你安装了Axis SDK吗?或者您是否已注册所需的ActiveX DLL文件?

要在64位操作系统上构建32位应用程序,您必须注册32位DLL文件(以管理员身份):

  

C:\ Windows \ SysWOW64 \ regsvr32.exe&#34; \ path \ to \ AxisSDKActiveX.dll&#34; :: 32位ActiveX   C:\ Windows \ regsvr32.exe&#34; \ path \ to \ AxisSDKActiveX.dll&#34; :: 64位ActiveX

注意SysWOW64文件夹。它实际上包含32位工具和DLL文件。 理解这一点非常重要!

要查看当前注册的库,请使用RegDllView application。您还可以使用应用程序中的 F6 键来注册新库。