【问题标题】:COMException while instantiating a form containing an ActiveX control in a WPF window在 WPF 窗口中实例化包含 ActiveX 控件的表单时出现 COMException
【发布时间】:2014-01-03 18:21:04
【问题描述】:

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

例外

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

内部异常:类未注册

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 中)。


已添加以下引用:


内部异常

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

【问题讨论】:

  • 检查内部异常。
  • @RohitVats 感谢您抽出宝贵时间。我在底部添加了内部异常。请刷新
  • 似乎是一些 COM 异常,与 WPF 无关。对不起,但我不知道。 :(
  • COMException 的 ErrorCode 值是多少?
  • 您的 winforms 应用程序是否在 WPF 应用程序失败的同一台机器上成功运行?如果是,则可能是 64/32 位兼容性问题。您的 WPF 应用程序是 64 位的吗? winforms 应用呢?

标签: c# wpf winforms xaml activex


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    要在 64 位操作系统上构建 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 键来注册新库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-08
      • 1970-01-01
      • 1970-01-01
      • 2010-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      相关资源
      最近更新 更多