© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
8 replies
Akex

Object reference not set to an instance of an object.

root is an HtmlNode but when I try to access anything using SelectSingleNode or SelectNodes it will raise this error when trying to access any methods of them.

HtmlDocument doc = new();
doc.LoadHtml($"{url}/page/{page}/");

HtmlNode root = doc.DocumentNode;
Console.WriteLine(root.GetType());
Console.WriteLine(root.SelectSingleNode("//div").GetType());
HtmlDocument doc = new();
doc.LoadHtml($"{url}/page/{page}/");

HtmlNode root = doc.DocumentNode;
Console.WriteLine(root.GetType());
Console.WriteLine(root.SelectSingleNode("//div").GetType());
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Object reference not set to an instance of an object.
C#CC# / help
10mo ago
"Object reference not set to an instance of an object"
C#CC# / help
17mo ago
✅ Object reference not set to an instance of an object?
C#CC# / help
2y ago
Object reference not set to an instance of an object
C#CC# / help
2y ago