let me in LINQ: why does the reference to the object not indicate a copy of the object?
-
The method, using AgilityHtmlPak, should eject the links from the page, throwing out the process in an increasingly unnecessary manner (links to pictures, encores, etc.). Everything works well separately, and together makes a mistake:
An unhandled exception of type 'System.NullReferenceException' occurred in Crawler.exe Additional information: The reference to the facility does not indicate a copy of the facility.
This method is:
public List<string> ParserHtml(string uri, string baseUrl) { var webGet = new HtmlWeb(); var document = webGet.Load(uri);
var linksOnPage = (from lnks in document.DocumentNode.Descendants() where lnks.Name == "a" && lnks.Attributes["href"] != null let lnk1 = lnks.Attributes["href"].Value let lnk2 = !lnk1.Contains("rss") ? lnk1 : null let lnk3 = !lnk2.StartsWith("mailto:") ? lnk2 : null select lnk3 ).Distinct().ToList(); return linksOnPage; }
These pieces of code themselves are working, for example:
let lnk2 = !lnk1.Contains("rss") ? lnk1 : null
//let lnk3 = !lnk2.StartsWith("mailto:") ? lnk2 : null
select lnk2
or so:
//let lnk2 = !lnk1.Contains("rss") ? lnk1 : null
let lnk3 = !lnk1.StartsWith("mailto:") ? lnk1 : null
select lnk3
If you don't know what's going on, it's a mistake to calculate lnk3 from lnk2, it's the opposite.
-
Okay, you met a line starting with
rss
♪
When computedlnk2
You got it.null
You don't have a facility, and you're trying to figure it out.lnk3
cause his method.
Iflnk2
If you don't use it, you'll replace it.let lnk2 = !lnk1.Contains("rss") ? lnk1 : null
♪let lnk2 = !lnk1.Contains("rss") ? lnk1 : ""
♪ It won't break the logic of the request.
Or do it.null
when computedlnk3
:lnk3 = lnk2==null?null:!lnk2.StartsWith("mailto:") ? lnk2 : null