I am using the mshtml library inside a VB.NET console application to extract some data from an http request.
The code is as follows:
Dim htmlDocument As IHTMLDocument2
For i As Integer = 0 To 10
searchHtml = getHtml(url)
htmlDocument = New HTMLDocumentClass()
htmlDocument.write(searchHtml)
htmlDocument.close()
Dim results As IHTMLElement = htmlDocument.body.all.item("ires")
For Each li As IHTMLElement In results.all.tags("li")
Dim element As IHTMLElement = li.all.tags("cite")(0)
If element.innerText.ToLower().Contains(text) Then
' Do Something here
Exit For
End If
Next
Next
The code above is called recursively from another method.
I can run my code in debug and it works time after time with no problem.
If I compile the exe and run it then I receive one of two errors. Initially I got an "Object reference not set to an instance of an object" after 11 calls to the above. This is repeatable and always occurs after 11 iterations.
If I add a Threading.Thread.Sleep(1000) before the above and re-compile I get the "Access is denied" error, again after a certain number of iterations.