Closed
Description
Issue:
A NullReferenceException
is being thrown when trying to call Next
that has no result.
Scenario:
Assuming document
is a CQ
object, I am making a call similar to:
var elem = document["#content.results > table > tbody > tr > td:nth-child(1) > a:nth-child(1)"].First();
// Do something with elem
var link = elem.Parent().Next("td").Children("a").First();
// NullReferenceException thrown.
In fact, there is no Next("td")
, but as I understand it, the call should fail silently and return an empty CQ
object. Instead, a NullReferenceException
is thrown. Let me know if I can provide more useful diagnostic information.
Exception Details:
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=CsQuery
StackTrace:
at CsQuery.Engine.SelectorEngine.Select(IEnumerable`1 context)
at CsQuery.Engine.Selector.Select(IDomDocument document, IEnumerable`1 context)
at CsQuery.Engine.Selector.<Filter>d__6.MoveNext()
at CsQuery.CQ.AddSelection(IEnumerable`1 elements)
at CsQuery.CQ.ConfigureNewInstance(CQ dom, IEnumerable`1 elements, CQ context)
at CsQuery.CQ.NewInstance(IEnumerable`1 elements, CQ context)
at CsQuery.CQ.FilterIfSelector(String selector, IEnumerable`1 list, SelectionSetOrder order)
at CsQuery.CQ.nextPrevImpl(String selector, Boolean next)
at CsQuery.CQ.Next(String selector)
...