Bug 19987 - Fatal exception when doing ToArray on a linq statement
Summary: Fatal exception when doing ToArray on a linq statement
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-05-22 05:24 UTC by Svein Arne Ackenhausen
Modified: 2014-05-23 10:02 UTC (History)
2 users (show)

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:

Description Svein Arne Ackenhausen 2014-05-22 05:24:29 UTC

I get this error randomly when Doing Enumerable.ToArray()

[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds
  at System.Array.Copy (System.Array sourceArray, Int32 sourceIndex, System.Array destinationArray, Int32 destinationIndex, Int32 length) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[System.String].CopyTo (System.String[] array, Int32 arrayIndex) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable.ToArray[String] (IEnumerable`1 source) [0x00000] in <filename unknown>:0 
  at OpenIDE.CodeEngine.Core.Endpoints.EventEndpoint.Send (System.String message) [0x00000] in <filename unknown>:0 
  at OpenIDE.CodeEngine.Core.ChangeTrackers.PluginFileTracker.handle (OpenIDE.CodeEngine.Core.ChangeTrackers.Change file) [0x00000] in <filename unknown>:0 
  at OpenIDE.CodeEngine.Core.ChangeTrackers.PluginFileTracker.<handleChanges>m__4 (OpenIDE.CodeEngine.Core.ChangeTrackers.Change x) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[OpenIDE.CodeEngine.Core.ChangeTrackers.Change].ForEach (System.Action`1 action) [0x00000] in <filename unknown>:0 
  at OpenIDE.CodeEngine.Core.ChangeTrackers.PluginFileTracker.handleChanges (System.Collections.Generic.Stack`1 buffer) [0x00000] in <filename unknown>:0 
  at OpenIDE.CodeEngine.Core.ChangeTrackers.FileChangeTracker.startChangeHandler (System.Object state) [0x00000] in <filename unknown>:0 
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0
Comment 1 Miguel de Icaza [MSFT] 2014-05-23 10:02:04 UTC
Chances are this is a race condition in your code: some thread is adding elements to the list, while you are performing the copy.   

You can provide a test case for us to investigate