Bug 3705 - Using GroupBy on a XPathNavigator Enumerable always returns a collection of the last item.
Summary: Using GroupBy on a XPathNavigator Enumerable always returns a collection of t...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-01 13:41 UTC by Tom Hindle
Modified: 2012-03-08 04:14 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
test case showing bug. (2.13 KB, text/x-csharp)
2012-03-01 13:41 UTC, Tom Hindle
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Tom Hindle 2012-03-01 13:41:43 UTC
Created attachment 1446 [details]
test case showing bug.

Attached test case showing bug.

Using certain linq methods on a XPathNavigator collection always returns the last
item in the resultant set duplicated, replacing all the expected entries.

IE.

given:
var res1 = xPathNaviagator.Select(somexPath)
.Cast<XPathNavigator>()
.OrderBy(someOrderingDelegate);
var res2 = xPathNaviagator.Select(somexPath)
.Cast<XPathNavigator>()
.OrderBy(someOrderingDelegate);
where:
somexPath returns any non empty set on data contained in xPathNaviagator.
and someOrderingDelegate is performs some arbitrary ordering.

then:
this is always true regardless of data:
res1.First().Value == res2.Last().Value);

Expected results of test case:

Test for GroupBy
<Note>
  <Reference>a</Reference>Some text1</Note>
<Note>
  <Reference>a</Reference>Some text3</Note>
<Note>
  <Reference>b</Reference>Some text2</Note>
Test for OrderBy
<Note>
  <Reference>a</Reference>Some text1</Note>
<Note>
  <Reference>a</Reference>Some text3</Note>
<Note>
  <Reference>b</Reference>Some text2</Note>

Actual results of test case:

Test for GroupBy
<Note>
  <Reference>a</Reference>Some text3</Note>
<Note>
  <Reference>a</Reference>Some text3</Note>
<Note>
  <Reference>a</Reference>Some text3</Note>
Test for OrderBy
<Note>
  <Reference>a</Reference>Some text3</Note>
<Note>
  <Reference>a</Reference>Some text3</Note>
<Note>
  <Reference>a</Reference>Some text3</Note>
Comment 1 Tom Hindle 2012-03-01 13:48:21 UTC
Note a work around for this bug is cloning the XPathNaviagator before performing the OrderBy or GroupBy for example:

xPathNaviagator.Select(somexPath)
.Cast<XPathNavigator>()
.Select(nav => nav.Clone())
.OrderBy(someOrderingDelegate);
Comment 2 Atsushi Eno 2012-03-08 03:34:02 UTC
Fixed in git master (b88e6a3). Thanks for the report.
Comment 3 Atsushi Eno 2012-03-08 03:36:21 UTC
Oops, the second case was not really fixed yet :(
Comment 4 Atsushi Eno 2012-03-08 04:14:48 UTC
The real fix is done in git master fe6e513.