【问题标题】:C# System.AccessViolationException and System.Runtime.InteropServices.SEHExceptionC# System.AccessViolationException 和 System.Runtime.InteropServices.SEHException
【发布时间】:2013-12-22 20:35:35
【问题描述】:

我们正在使用 C# 创建一个漫画书应用程序,并像往常一样在启动时创建一个 mainForm,然后当按下“1”键时,会弹出一个名为 detailForm 的新表单,显示所选漫画书的详细信息。如果您在 detailForm 上再次按“1”,还会创建第三种表单,这将打开另一个名为 ComicForm 的表单,显示实际的漫画书。

当您按“1”从 mainForm 转到 detailForm,然后立即按“2”返回 mainForm 时,我们的问题就开始了。当你这样做时,我们会得到这些异常中的任何一个。它不一致,可能会显示 System.AccessViolationException 或 System.Runtime.InteropServices.SEHException。

我们在 detailForm 上有一个 COM 对象,它显示了一个特定于每个漫画人物的 youtube 视频。

每次构建项目时都会抛出2个警告:

1>  COM Reference 'AcroPDFLib' is the interop assembly for ActiveX control 'AxAcroPDFLib' but was marked to be linked by the compiler with the /link flag. This COM reference will be treated as a reference and will not be linked.

1>  COM Reference 'ShockwaveFlashObjects' is the interop assembly for ActiveX control 'AxShockwaveFlashObjects' but was marked to be linked by the compiler with the /link flag. This COM reference will be treated as a reference and will not be linked.

运行这段代码后,每次都会崩溃:

private void detailForm_KeyDown_1(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.D2)
        {
            player.controls.stop();
            this.Close();
        }

        if (e.KeyData == Keys.D1)
        {
            this.Close();
            player.controls.stop();
            ComicForm comicShow = new ComicForm(newComic);
            comicShow.Show();
            comicShow.Focus();
        }
    }

崩溃后,它在 Program.cs 中突出显示,但实际上并没有运行它:

Application.Run(new MainForm());

【问题讨论】:

  • 您找到解决方案了吗?

标签: c# winforms exception com event-handling


【解决方案1】:

如果尚未设置,请在 Visual Studio 项目的引用中找到 ActiveX 的引用,选择引用并通过属性窗口查看其属性,查找“嵌入互操作类型”属性并将其设置为“False” ”。

这可能会解决问题。

【讨论】:

  • ActiveX 引用的“嵌入互操作类型”已设置为 false。不过,感谢您的建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2012-05-02
  • 2010-09-15
  • 1970-01-01
  • 2012-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多