Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:02:39+00:00 2026-06-04T07:02:39+00:00

I have spent way too much time trying to sort this little issue out.

  • 0

I have spent way too much time trying to sort this little issue out. I have narrowed down the issue to the exact procedure that throws the error. Yes, I have used Google.. Just throwing that out there before some wise guy replies “search google”!

Anyways, here:


Try
    Dim tempSource as String = Nothing
    Console.WriteLine("Loading document...")

    Dim FILE_NAME As String = "C:\pathto\file.txt"
    If System.IO.File.Exists(FILE_NAME) = True Then
        Dim objReader As New System.IO.StreamReader(FILE_NAME)
        tempSource = objReader.ReadToEnd
        objReader.Close()
        Console.WriteLine("Loaded the document!")
    Else
        Console.WriteLine("Error loading document!")
        MsgBox("Error loading document!")
        Exit Sub
    End If

    Dim doc As HtmlDocument = Nothing
    If tempSource IsNot Nothing Then
        Console.WriteLine("Temp Source was not nothing, so loading HAP doc")
        doc.Load(tempSource)  '<--- This is where the error is!!!!!
        Console.WriteLine("HAP doc loaded!")
    Else
        Console.WriteLine("Error: Unable to load source file into parser!")
        MsgBox("Error: Unable to load source file into parser!")
        Exit Sub
    End If
    Console.WriteLine("Document loaded!")
    Console.WriteLine("Processing...")

    For Each node As HtmlNode In doc.DocumentNode.Elements("//site")
        'my code to process each element here
        'not important because my app doesnt get this far lol
    Next

Catch ex as Exception
    Console.Writeline("Caught Exception: {0}", ex.Message)
End Try

I am loading a text file, that contains about 1100 lines, and each line is going to be processed with HTML Agility Pack. From what I can tell, when it runs “doc.loadhtml(richtextbox1)”, it throws the error. I also have tried to load the file into a string, and load the string with “doc.loadhtml(thestring)”. It doesn’t make a difference, still errors.

Here are is a sample of how each line looks:


<Site Index="" Name="" Group="" PR="" />
<Site Index="" Name="" Group="" PR="" />
<Site Index="" Name="" Group="" PR="" />
<Site Index="" Name="" Group="" PR="" />
<Site Index="" Name="" Group="" PR="" />
<Site Index="" Name="" Group="" PR="" />

I am using HTML Agility Pack, however the above is what is on every line, about 1100 lines! For testing, I have a smaller text file made of about 50 lines before I load up the 1100 line file 😉 There aren’t any HTML, HEAD, or BODY tags! They aren’t needed for my parsing. I am using HTML Agility Pack because it is easy to parse elements with. I can grab each value easily from each line.

I am not sure if maybe the error is because it technically isn’t HTML? Meaning since the loaded code doesn’t have an HTML or BODY tag, that it errors? I wanted to get this question posted, and while I am waiting on some answers, I am going to parse the document another way. Just curious as to what the deal is and why HTML Agility Pack isn’t working. More of a proof of concept then anything, for my own learning and knowledge.

Here is the error I get (btw the on the doc.load() line, is where it throws the exception):


Object reference not set to an instance of an object

Last Note: The routine is on a background thread. I have used multi-threading before, and have delegates created for deeper in the code. Maybe I am just overlooking something, I did write most of the code last night at like 3 am lol.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:02:40+00:00Added an answer on June 4, 2026 at 7:02 am

    It looks like you’re not initializing the document…

    Dim doc As HtmlDocument = Nothing
    

    I don’t write VB, mostly C#, Java and C++, but doc = Nothing seems like doc = null and when you invoke the load(...) method on a null object, I would expect to see the “Object reference not set to an instance of an object” exception.

    Try initializing the doc to an actual HtmlDocument:

    Dim doc As New HtmlDocument
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent WAY too much time trying to figure out how to pull
This is probably simple, but I have spent way too much time trying to
I have spent way too much time trying to solve what seems to be
I am having an issue that I have spend way too much time trying
I have spent way too much time looking for the files owner icon to
I have spent way too much time (over an hour) on what I though
I have a feeling I've spent too much time on this problem and have
Have spent an hour trying to solve this - but to no avail. I'm
I have spent hours in this problem and my fellows couldn't help me out.
I have spent all Friday and Saturday on this and I am running out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.