3
for (int x = 0; x < 50; x++)
{
    NSoupClient.Connect("https://steamcommunity.com/gid/" + x)
               .UserAgent("Firefox")
               .Timeout(10000)
               .Get();
}

This piece of code will throw me this error (and it always stops when the int is 5):

An unhandled exception of type 'System.NullReferenceException' occurred in NSoup.dll

enter image description here

Tatranskymedved
  • 4,194
  • 3
  • 21
  • 47
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – mybirthname Nov 21 '16 at 06:24
  • I've seen this before, but what is null?? –  Nov 21 '16 at 06:24
  • Seems You are not the only having the issue - https://nsoup.codeplex.com/workitem/8 Seems as an issue with library itself. – Tatranskymedved Nov 21 '16 at 06:28

1 Answers1

0

I fixed this using a WebClient to download the page.

using (WebClient wc = new WebClient())
{
    wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4");
    string html = wc.DownloadString(url);
    Document document = NSoupClient.Parse(html);
}
Florin Birgu
  • 495
  • 7
  • 12