Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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
Developer Community or GitHub 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.
Created attachment 13688 [details]
Sample project showing the issue
There event won't be an exception or crash by me; it just stops the app. (Though I've earlier written an extension method for this named ToListSafe, which made an isEmpty-check before calling ToList on it, so I could swear once there was an exception there...)
Attached the Xamarin.Mac.Samples/MacTables project forked with these 2 rows:
var emptyIndexSet = ProductTable.SelectedRows;
var smg = emptyIndexSet.ToList(); // MainWindow.cs:39
If you run the project, the app window won't appear. You can see that execution stops at row 39 when you click the "pause" (||) button in Xamarin Studio; or just put a breakpoint on that row; you can't step over it. It just freezes the app exectuion
The following is all that is needed to reproduce:
static void Main (string args)
var emptyIndexSet = new NSIndexSet ();
var smg = emptyIndexSet.ToList();
So under the hood, this is because FirstIndex and LastIndex are giving us bogus data and we're looping forever looking for the end of the list.
Fixed in master / 777d171b95d9a255c7c9ccfcbe1c86576fc6002f
This won't make it until C7, but testing against Count == 0 before calling ToList is the best workaround.
Thanks for the report with repro case. It made fixing it easy!
If someone would need a fast and universal workaround until the fix, I use this extension method everywhere where touching NSIndexSet with LinQ:
public static IEnumerable<nuint> EnumerateSafe(this NSIndexSet nsIndexSet)
if(nsIndexSet == null || nsIndexSet.Count == 0)
foreach(var nuint in nsIndexSet)
yield return nuint;