Bug 3903 - Crash in Linq statement on System.Array with a 2D array of structs
Summary: Crash in Linq statement on System.Array with a 2D array of structs
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: Macintosh Mac OS
: High major
Target Milestone: ---
Assignee: Rodrigo Kumpera
Depends on:
Reported: 2012-03-15 00:05 UTC by Adam Kemp
Modified: 2017-08-28 15:04 UTC (History)
5 users (show)

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

desktop test case (306 bytes, application/octet-stream)
2012-03-15 04:38 UTC, Rolf Bjarne Kvinge [MSFT]

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 Adam Kemp 2012-03-15 00:05:56 UTC
The following code crashes the app in the simulator (and I am assuming on the device as well). Note that this is appears to be a runtime crash, not just an uncaught .Net exception.

private struct Foo

public class TestClass
    public void TestMethod()
        Foo[][] array = new Foo[][] { new Foo[0] };
        // The next line will crash
        List<object> list = array.Cast<object>().Select((arg) => arg).ToList();

Things that I tried which do not crash:
1. Change Foo to a class instead of struct.
2. Make the array 1D instead of 2D.
3. Don't do the Cast.
4. Don't do the Select.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-03-15 04:38:32 UTC
Created attachment 1519 [details]
desktop test case

Attached is a test case that shows this problem with gmcs.

Note that it only happens when compiled for the 2.0 profile, not the 4.0 profile (I tried compiling with gmcs from both 2.10 and master, in both cases the executable crashed when executed with either 2.10 or master - and it never crashes when compiled with dmcs).
Comment 2 Rodrigo Kumpera 2012-04-24 15:52:11 UTC
Fixed on 2.10 and master. Thanks for the repro.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-04-24 17:13:21 UTC
Also fixed in MonoTouch (master: cbed2c8d07). The fix will be included in 5.3.3.