It seems like you might not checking null before executing the above line
if (doc.DocumentNode.SelectNodes(@"//a[@href]" != null){
foreach (HtmlNode link in doc.DocumentNode.SelectNodes(@"//a[@href]")){
//your code goes here
}
}
please share some more code too if above does not work.
Please let me know in case of any concerns.