C#System.AccessViolationException和System.Runtime.InteropServices.SEHException

时间:2013-12-05 18:32:09

标签: c# winforms exception com event-handling

我们正在使用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());

1 个答案:

答案 0 :(得分:1)

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

这可能会解决问题。

相关问题