C#System.AccessViolationException和System.Runtime.InteropServices.SEHException [英] C# System.AccessViolationException and System.Runtime.InteropServices.SEHException

查看:698
本文介绍了C#System.AccessViolationException和System.Runtime.InteropServices.SEHException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用C#创建一个漫画应用程序,并且在启动时创建一个mainForm,像往常一样,然后当按下1键时,会出现一个名为detailForm的新窗体,显示所选漫画的详细信息。还有一个第三种形式,如果你再次按下'1'在detailsForm,将创建另一种形式叫comicForm,显示实际的漫画书。

We are creating a comic book application using C# and are having a mainForm created on startup as usual and then when pressing the '1' key a new form called detailForm pops up showing the details of the selected comic book. There is a also a third form that is created if you press '1' again on the detailForm that will bring up another form called comicForm that shows the actual comic book.

我们的问题开始,当你按'1'去从mainForm的detailForm,然后立即按'2'回到mainForm。当你这样做,我们得到这两个异常。它不一致,可以显示System.AccessViolationException或System.Runtime.InteropServices.SEHException。

Our problem begins when you press '1' to go to the detailForm from the mainForm and then immediately press '2' to go back to the mainForm. When you do this, we get either of these exception. It is not consistent and can show either a System.AccessViolationException or a System.Runtime.InteropServices.SEHException.

我们在detailForm上有一个COM对象,显示一个youtube视频

We have a COM object on the detailForm that shows a youtube video specific to each comic book character.

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

There are 2 warnings being thrown when building the project each time:

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.

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

After it runs this code segment, it crashes each time:

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 ,但实际上不运行它:

After the crash, it highlights this in Program.cs, but doesn't actually run it:

Application.Run(new MainForm());


推荐答案

如果尚未设置,找到ActiveX的引用在您的visual studio项目的引用中,选择引用并通过属性窗口查看其属性,查找Embed Interop Type属性并将其设置为False。

If not already set, Find the reference of the ActiveX in your references of your visual studio project, select the reference and view it's properties via the properties window, look for the "Embed Interop Type" property and set it "to False".

这可能解决了问题。

这篇关于C#System.AccessViolationException和System.Runtime.InteropServices.SEHException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆