You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
varelem=document["#content.results > table > tbody > tr > td:nth-child(1) > a:nth-child(1)"].First();// Do something with elemvarlink=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)
...
I just tried this with some random HTML that matches nothing (so there are no results at any step) and it works fine. Can you confirm you're using 1.3, and if so show me some html that fails with this selector?
Fix on github now. There will be an update to nuget whenever I finish dealing with the encoding issue (#52) but the dist code here should solve this problem.
Activity
jamietre commentedon Oct 31, 2012
I just tried this with some random HTML that matches nothing (so there are no results at any step) and it works fine. Can you confirm you're using 1.3, and if so show me some html that fails with this selector?
musabhusaini commentedon Oct 31, 2012
Yes, I am using 1.3. I loaded up this page using
CQ.CreateDocument(string html)and the following code failed for me:jamietre commentedon Oct 31, 2012
OK tracked it down, fix shortly.
musabhusaini commentedon Oct 31, 2012
Great!
Fixes for Issue #57, Issue #56
jamietre commentedon Oct 31, 2012
Fix on github now. There will be an update to nuget whenever I finish dealing with the encoding issue (#52) but the dist code here should solve this problem.