Trying to trap Internet Explorer BeforeNavigate2 event


Jul 29, 2008
Programming Experience
I am trying to trap the BeforeNavigate2 event of the ShDocVw.InternetExplorer object. When I try to navigate in one of the internet explorer windows, the handler fires, but I get an error that says:
An exception of type 'System.NotImplementedException' occured in mscorlib.dll and wasn't handled before a managed/native boundary

Additional information: Variant.ToObject cannot handle16396

Below is my code:
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SWs As New SHDocVw.ShellWindows
Dim IE As SHDocVw.InternetExplorer

For Each IE In SWs
AddHandler IE.BeforeNavigate2, AddressOf WebBrowser_BeforeNavigate2
Call MsgBox("Done.", vbOKOnly, "Done.")
End Sub
Private Sub WebBrowser_BeforeNavigate2(ByVal pDisp As Object, ByRef URL As Object, ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
' Rest of my code
End Sub
End Class

I'm currently out of practice with VB.NET, and I wouldn't even know where to begin trying to solve this problem. Any help would be greatly appreciated. Thanks in advance.
Top Bottom