Bug 2558 - Using List.LastIndexOf on empty list gives System.ArgumentOutOfRangeException on Mono, but not .NET
Summary: Using List.LastIndexOf on empty list gives System.ArgumentOutOfRangeException...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Debugger ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-12-17 12:45 UTC by Kim Lindgren
Modified: 2011-12-19 06:24 UTC (History)
2 users (show)

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

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 Kim Lindgren 2011-12-17 12:45:06 UTC
Attempting to use List.LastIndexOf on an empty list in Mono yields a System.ArgumentOutOfRangeException. In .NET this function returns -1 on empty lists.

Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of range.
  at System.Array.LastIndexOf[Int32] (System.Int32[] array, Int32 value, Int32 startIndex, Int32 count) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[System.Int32].LastIndexOf (Int32 item) [0x00000] in <filename unknown>:0 
  at Bearhug.Life.survives (System.Collections.Generic.List`1 dead_parents) [0x00000] in <filename unknown>:0 
  at Bearhug.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Argument is out of range.
  at System.Array.LastIndexOf[Int32] (System.Int32[] array, Int32 value, Int32 startIndex, Int32 count) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[System.Int32].LastIndexOf (Int32 item) [0x00000] in <filename unknown>:0 
  at Bearhug.Life.survives (System.Collections.Generic.List`1 dead_parents) [0x00000] in <filename unknown>:0 
  at Bearhug.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

Starting the list by adding an arbitrary item will work around this for the moment.
Comment 1 Zoltan Varga 2011-12-19 06:22:13 UTC
Fixed in HEAD/2.10 branch.
Comment 2 Zoltan Varga 2011-12-19 06:24:24 UTC
-> fixed.