3

I am using a webBrowser control to open PDF document in winforms, it works fine but when closing the application I get sometimes an error : "The Instruction at "0x2d864aa2" referenced memory at "0x00000008". The memory could not be "read". Is there a solution for this problem?

Regards.

DevTun
  • 865
  • 1
  • 8
  • 24

1 Answers1

5

Believe it or not, yesterday I've been banging my head against this exact same problem and here's the solution I've found. Add the following to the FormClosed event:

[DllImport("ole32.dll")]
private static extern void CoFreeUnusedLibraries();

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
    base.OnFormClosed(e);
    webBrowser1.Visible = false;
    while (webBrowser1.IsBusy)
    {
        Application.DoEvents();
    }
    webBrowser1.Dispose();
    CoFreeUnusedLibraries();
}

Actually it seems there's a bug in Adobe Acrobat 9.x causing this exception.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • It works. All I needed was to call the CoFreeUnusedLibraries() with DllImport. As I'm using WPF, I also had to ensure the AllowsTransparency of the window was turned off. – Rafael Ventura Jun 14 '17 at 13:46