I know that the null reference exception is thrown when a reference is made to something that is null or nothing. I’m getting the error but I can’t see what it is that is null.
My program (writen in VB.NET 2010) is one that allows non HTML folk to edit web pages and it works fine in the main Windows form I’ve created. We have a footer that uses a server side include file and I set up a dialog box to allow users to edit the contents of the footer in a WebBrowser control.
My dialog box load event is coded as follows:
Private Sub FooterDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strInput As String
strInput = My.Computer.FileSystem.ReadAllText(LocalWebSiteFolder & “footer.html”)
With Me.WebBrowser1
.Navigate(LocalWebSiteFolder & “blank.html”)
.Document.ExecCommand(“EditMode”, False, Nothing)
.Document.Body.InnerHtml = strInput
.Focus()
End With
End Sub
The null reference exception occurs on the line where I try to set the InnerHTML of the WebBrowser document to my strInput variable. Before you ask, the reason I navigate to blank.html before inserting the HTML text from footer.html is simply the footer contains no formatting and the Webbrowser looks awful without it. Anyway, I use the same technique on the main form and it works fine.
Any ideas where I’m going wrong?