Monday, 1 October 2007

VB 2005 WebBrowser app crashes with the error "The instruction at "0x30cb0a4f" referenced memory at "0x00000000". The memory could not be written"

when closing VB 2005 windows application, its showing the error message " Application.exe - Application Error The instruction at "0x30cb0a4f" referenced memory at "0x00000000". The memory could not be written" . Click on OK to terminate the program.". It happens if the WebBrowser control loads a SharePoint web site.

Resolution:
---------------
Assign "about:blank" as the url property of the web browser control and in the form load use the Navigate function to display the website


It is caused by WebBrowser control.

1. The form can be shown when the WebBrowser control loads a SharePoint site. The application crashes when the form is unloaded. So we add the following code to work around the problem. Basically, load "about:blank" on WebBrowser control before the form is unloaded.

Public Class Form1
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If WebBrowser1.Url.AbsoluteUri <> "about:blank" Then
Me.Visible = False
AddHandler WebBrowser1.DocumentCompleted, AddressOf WebBrowser1_FinishClosingForm
WebBrowser1.Navigate("about:blank")
e.Cancel = True
End If
End Sub

Private Sub WebBrowser1_FinishClosingForm(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
CoFreeUnusedLibraries()
Me.Close()
End Sub
End Class