Bug 1824 - Simple linq query crashes on device
Summary: Simple linq query crashes on device
Status: CLOSED DUPLICATE of bug 587
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Macintosh Mac OS
: Highest blocker
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-11-02 09:28 UTC by David Black
Modified: 2012-01-04 11:23 UTC (History)
6 users (show)

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

Sample project (8.56 KB, application/x-zip-compressed)
2011-11-03 10:15 UTC, AndyW
Image for the bug (51.49 KB, image/png)
2011-11-04 13:43 UTC, narayanp

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 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.

Related Links:

Description David Black 2011-11-02 09:28:58 UTC
After upgrading to 5.01 I get the following exception on the DEVICE (not the emulator)

Error - Attempting to JIT compile method 'System.Linq.Enumerable:Select<Casewise.Navigator.Services.Diagram.FlyweightJoiner, Casewise.Navigator.Shared.NavigatorJoiner> (System.Collections.Generic.IEnumerable`1<Casewise.Navigator.Services.Diagram.FlyweightJoiner>,System.Func`2<Casewise.Navigator.Services.Diagram.FlyweightJoiner, Casewise.Navigator.Shared.NavigatorJoiner>)' while running with --aot-only.
 (1.524414 MB)
Error -   at Casewise.Navigator.Services.Diagram.FlyweightDiagram.ToCommonRepresentation () [0x00000] in /Users/davidb/Projects/Navigator/Casewise.Navigator.Services/Partials/FlyweightDiagram.cs:17 
  at Casewise.Navigator.Business.DiagramBusiness.DiagramLoadComplete (System.Object sender, Casewise.Navigator.Services.Diagram.GetDiagramCompletedEventArgs args) [0x000b5] in /Users/davidb/Projects/Navigator/Casewise.Navigator.Business/DiagramBusiness.cs:67  (1.52832 MB)

In the following class that uses a very, very, very basic piece of Linq

public partial class FlyweightJoiner
		public NavigatorJoiner ToCommonRepresentation ()
			var res = new NavigatorJoiner ()
				FromSequence = this.FromSequence,
				ToSequence = this.ToSequence,
				Points = (from p in this.Points select new System.Drawing.PointF(p.X, p.Y)).ToArray(),
			return res;
Comment 1 Chris Hardy [MSFT] 2011-11-02 10:39:10 UTC
Hi David,

Could you provide a simple test case of the issue, we obviously don't know what your NavigatorJoiner class is doing to these variables, I have created this sample - https://gist.github.com/06957a70c9981f806857 and this runs fine on device with 5.0.1.


Chris Hardy
Comment 2 AndyW 2011-11-03 06:43:18 UTC
Since upgrading to MonoTouch 5.0.1 I see the same. 

I've written a test below to help further:

using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace test
	public class Application
		static void Main (string[] args)
			UIApplication.Main (args);
	class Things
		public string Property;
	// The name AppDelegate is referenced in the MainWindow.xib file.
	public partial class AppDelegate : UIApplicationDelegate
		Dictionary<string, List<Things>> _thingys = new Dictionary<string, List<Things>>();
		// This method is invoked when the application has loaded its UI and its ready to run
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
			// If you have defined a view, add it here:
			// window.AddSubview (navigationController.View);
			var things1 = new List<Things> ();
			things1.Add (new Things{Property = "1,1"});
			things1.Add (new Things{Property = "1,2"});
			_thingys.Add ("Things1", things1);
			var things2 = new List<Things> ();
			things2.Add (new Things{Property = "2,1"});
			things2.Add (new Things{Property = "2,2"});
			_thingys.Add ("Things2", things2);
			Console.WriteLine (_thingys.ElementAt (1)); // crahses here
			window.MakeKeyAndVisible ();
			return true;
		// This method is required in iPhoneOS 3.0
		public override void OnActivated (UIApplication application)
Comment 3 Chris Hardy [MSFT] 2011-11-03 07:14:27 UTC
Hi Trip,

What's the crash you're getting show?

I've tried this on device and I just get this returned:

UIKitApplication:test[0x3b04][12536] <Notice>: [Things2, System.Collections.Generic.List`1[test.Things]]

Which looks fine to me.

Could you also copy in what you see in the "Version Info" tab in MonoDevelop -> About MonoDevelop -> Version Info tab.

Thanks in advanced,

Chris Hardy
Comment 4 Sebastien Pouliot 2011-11-03 09:14:45 UTC
You are hitting one of the full-AOT limitations, like the one below:

This can be hit indirectly when doing LINQ queries since a lot of (unseen) things happens under the hood when a LINQ statement is executed.

Since, even in those cases, the AOT compiler might (or not) find "hints" to compile the required code it's very important to provide a full, self-contained, test case (e.g. a zip file with your solution) so we can reproduce it and come up with a fix or a workaround to help you.

Trip, could it be that your original test case was using a 'struct' for Things instead of a class ?
Comment 5 AndyW 2011-11-03 09:34:28 UTC
Sorry I should have added you need to change to "Don't Link Assemblies".

The excpetion is a System.ExecutionEngineException - Attempting to JIT compile method 'System.Linq.Check:Source (object)' while running with --aot-only.

Things is a class, and the code I provide does fail on my device. MonoDevelop Version 2.8.2

To be honest it smells of the one I reported last time.
Comment 6 Sebastien Pouliot 2011-11-03 09:58:31 UTC
Please unless you're 100% sure this is the same issue, with the same message and stack trace, always open a new bug report. It's much easier to merge them than to split them and multiple-issues bug reports tends to fix only parts of the problems (and no one can make sense of the comments/history afterward).
Comment 7 Chris Hardy [MSFT] 2011-11-03 10:04:54 UTC

Could you please zip up the project and attach it to this bug so we can reproduce this issue. I have tried changing the Linker status to Don't Link, Link SDK and Link All and still can't reproduce.

Comment 9 AndyW 2011-11-03 10:15:07 UTC
Created attachment 816 [details]
Sample project
Comment 10 Sebastien Pouliot 2011-11-03 11:09:16 UTC
We found the issue and will test it (with your test cases) before releasing 5.0.2 asap.
Thanks for the test cases.
Comment 11 narayanp 2011-11-04 13:43:28 UTC
We have re-tested this bug on MT 5.0.2 and run the "Test" application (Which is attached in this bug). We observed that application run successfully on Device and Simulator without any error/exception.

Please refer the attached screen shot "Issue" for same.

Please let us know if we missed anything. If this is OK, we can close this issue.
Comment 12 narayanp 2011-11-04 13:43:57 UTC
Created attachment 825 [details]
Image for the bug
Comment 13 Chris Hardy [MSFT] 2011-11-04 14:19:53 UTC
I can confirm that 5.0.2 fixes this issue and the screenshot looks correct.
Comment 14 Sebastien Pouliot 2011-11-04 22:24:10 UTC
Fixed in 5.0.2 (as our mono revision was fixed in this build).

*** This bug has been marked as a duplicate of bug 587 ***