C# System.AccessViolationException and System.Runt

2019-07-19 06:53发布

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.

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.

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();
        }
    }

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

Application.Run(new MainForm());

1条回答
在下西门庆
2楼-- · 2019-07-19 07:33

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".

This might fix the issue.

查看更多
登录 后发表回答