But in .NET Core, the first result is correct, then it throws a NullReferenceException on iterating to the next result.
<picture_url>url1</picture_url>
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Xml.XPath.XNodeNavigator.MoveToNext(XPathNodeType type)
at Wmhelp.XPath2.Iterator.ChildOverDescendantsNodeIterator.NextItem()
at Wmhelp.XPath2.XPath2NodeIterator.MoveNext()
at Wmhelp.XPath2.XPath2NodeIterator.Enumerator.MoveNext()
at Wmhelp.XPath2.XNodeExtensions.XPath2Select(XNode node, XPath2Expression expression, Object arg)+MoveNext()
The code
void Main()
{
XContainer c = XDocument.Parse(html);
IEnumerable<Object> select = c.XPath2Select("//pictures/picture/picture_url");
foreach(Object o in select)
{
Console.WriteLine(o);
}
}
const String html = @"
<pictures>
<picture>
<picture_url>url1</picture_url>
</picture>
<picture>
<picture_url>url2</picture_url>
</picture>
<picture>
<picture_url>url3</picture_url>
</picture>
</pictures>";
The code below returns as expected on .NET framework:
But in .NET Core, the first result is correct, then it throws a NullReferenceException on iterating to the next result.
The code
Thoughts: There seems to be a switch on Clone() depending on the framework in https://github.com/StefH/XPath2.Net/blob/b4639abfa95fe7495209e4f0f54330d9c5ba5b9c/src/XPath2/XPath2NodeIterator.cs#L210, could it be the cause?