Bug 3710 - LINQ FirstOrDefault throwing System.ExecutionEngineException
Summary: LINQ FirstOrDefault throwing System.ExecutionEngineException
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-03-01 19:58 UTC by danmiser
Modified: 2012-03-03 17:14 UTC (History)
3 users (show)

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


Attachments
Sample to show FirstOrDefault bug (11.35 KB, application/zip)
2012-03-01 19:58 UTC, danmiser
Details


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:
Status:
RESOLVED FIXED

Description danmiser 2012-03-01 19:58:45 UTC
Created attachment 1451 [details]
Sample to show FirstOrDefault bug

Run the attached application. The crash report is below.

It works fine on the simulator.


Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:<FirstOrDefault`1>m__5A<System.Nullable`1<int>> (System.Nullable`1<int>)' while running with --aot-only.

  at System.Linq.Enumerable.First[Nullable`1] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00013] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:812 
  at System.Linq.Enumerable.FirstOrDefault[Nullable`1] (IEnumerable`1 source) [0x00006] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:857 
  at FirstOrDefaultBug.AppDelegate.<FinishedLaunching>m__0 (FirstOrDefaultBug.MachineMeter mm) [0x00000] in /Users/danmiser/code/bugs/FirstOrDefaultBug/FirstOrDefaultBug/AppDelegate.cs:43 
  at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator1D`2[FirstOrDefaultBug.MachineMeter,<>__AnonType0`2[FirstOrDefaultBug.MachineMeter,System.Int32]].MoveNext () [0x00000] in <filename unknown>:0 
  at FirstOrDefaultBug.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00108] in /Users/danmiser/code/bugs/FirstOrDefaultBug/FirstOrDefaultBug/AppDelegate.cs:50 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at FirstOrDefaultBug.Application.Main (System.String[] args) [0x00000] in /Users/danmiser/code/bugs/FirstOrDefaultBug/FirstOrDefaultBug/Main.cs:17 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:<FirstOrDefault`1>m__5A<System.Nullable`1<int>> (System.Nullable`1<int>)' while running with --aot-only.

  at System.Linq.Enumerable.First[Nullable`1] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00013] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:812 
  at System.Linq.Enumerable.FirstOrDefault[Nullable`1] (IEnumerable`1 source) [0x00006] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:857 
  at FirstOrDefaultBug.AppDelegate.<FinishedLaunching>m__0 (FirstOrDefaultBug.MachineMeter mm) [0x00000] in /Users/danmiser/code/bugs/FirstOrDefaultBug/FirstOrDefaultBug/AppDelegate.cs:43 
  at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator1D`2[FirstOrDefaultBug.MachineMeter,<>__AnonType0`2[FirstOrDefaultBug.MachineMeter,System.Int32]].MoveNext () [0x00000] in <filename unknown>:0 
  at FirstOrDefaultBug.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00108] in /Users/danmiser/code/bugs/FirstOrDefaultBug/FirstOrDefaultBug/AppDelegate.cs:50 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at FirstOrDefaultBug.Application.Main (System.String[] args) [0x00000] in /Users/danmiser/code/bugs/FirstOrDefaultBug/FirstOrDefaultBug/Main.cs:17 
Terminating runtime due to unhandled exception
Stacktrace:


Native stacktrace:

	0   FirstOrDefaultBug                   0x001da120 mono_handle_native_sigsegv + 280
	1   FirstOrDefaultBug                   0x001fce74 sigabrt_signal_handler + 180
	2   libsystem_c.dylib                   0x3323e539 _sigtramp + 48
	3   libsystem_c.dylib                   0x33233f5b pthread_kill + 54
	4   libsystem_c.dylib                   0x3322cfeb abort + 94
	5   FirstOrDefaultBug                   0x002b5f24 monoeg_g_logv + 152
	6   FirstOrDefaultBug                   0x002b5f70 monoeg_assertion_message + 52
	7   FirstOrDefaultBug                   0x001c3af8 mono_thread_abort + 148
	8   FirstOrDefaultBug                   0x001d9cec mono_handle_exception_internal + 3188
	9   FirstOrDefaultBug                   0x001d9ef0 mono_handle_exception + 24
	10  FirstOrDefaultBug                   0x001fba88 mono_arm_throw_exception + 172
	11  FirstOrDefaultBug                   0x001335ac throw_exception + 48
	12  FirstOrDefaultBug                   0x001c60c0 mono_jit_compile_method + 68
	13  FirstOrDefaultBug                   0x0026d688 mono_compile_method + 56
	14  FirstOrDefaultBug                   0x001db1d4 mono_delegate_trampoline + 596
	15  FirstOrDefaultBug                   0x00133094 generic_trampoline_delegate + 136
	16  FirstOrDefaultBug                   0x00008bc4 System_Linq_Enumerable_FirstOrDefault_System_Nullable_1_int_System_Collections_Generic_IEnumerable_1_System_Nullable_1_int + 264
	17  FirstOrDefaultBug                   0x00002f58 FirstOrDefaultBug_AppDelegate__FinishedLaunchingm__0_FirstOrDefaultBug_MachineMeter + 516
	18  FirstOrDefaultBug                   0x00053324 System_Linq_Enumerable__CreateSelectIteratorc__Iterator1D_2_MoveNext + 344
	19  FirstOrDefaultBug                   0x00002bf8 FirstOrDefaultBug_AppDelegate_FinishedLaunching_MonoTouch_UIKit_UIApplication_MonoTouch_Foundation_NSDictionary + 1968
	20  FirstOrDefaultBug                   0x00110cfc wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
	21  FirstOrDefaultBug                   0x001c676c mono_jit_runtime_invoke + 1644
	22  FirstOrDefaultBug                   0x0026ebec mono_runtime_invoke + 128
	23  FirstOrDefaultBug                   0x002cb304 monotouch_trampoline + 3228
	24  UIKit                               0x378307eb -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1186
	25  UIKit                               0x3782a3bd -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 396
	26  UIKit                               0x377f8921 -[UIApplication handleEvent:withNewEvent:] + 1016
	27  UIKit                               0x377f83bf -[UIApplication sendEvent:] + 54
	28  UIKit                               0x377f7d2d _UIApplicationHandleEvent + 5808
	29  GraphicsServices                    0x30c2adf3 PurpleEventCallback + 882
	30  CoreFoundation                      0x34423553 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
	31  CoreFoundation                      0x344234f5 __CFRunLoopDoSource1 + 140
	32  CoreFoundation                      0x34422343 __CFRunLoopRun + 1370
	33  CoreFoundation                      0x343a54dd CFRunLoopRunSpecific + 300
	34  CoreFoundation                      0x343a53a5 CFRunLoopRunInMode + 104
	35  UIKit                               0x37829457 -[UIApplication _run] + 550
	36  UIKit                               0x37826743 UIApplicationMain + 1090
	37  FirstOrDefaultBug                   0x00030540 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
	38  FirstOrDefaultBug                   0x00002330 FirstOrDefaultBug_Application_Main_string__ + 152
	39  FirstOrDefaultBug                   0x00110cfc wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
	40  FirstOrDefaultBug                   0x001c676c mono_jit_runtime_invoke + 1644
	41  FirstOrDefaultBug                   0x0026ebec mono_runtime_invoke + 128
	42  FirstOrDefaultBug                   0x00272e98 mono_runtime_exec_main + 436
	43  FirstOrDefaultBug                   0x00277b0c mono_runtime_run_main + 756
	44  FirstOrDefaultBug                   0x001caaf4 mono_jit_exec + 140
	45  FirstOrDefaultBug                   0x001c2d2c main + 1992
	46  FirstOrDefaultBug                   0x00002184 start + 52

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
Comment 1 danmiser 2012-03-01 20:58:21 UTC
Even simpler test case (no master/detail relationship):


var collectionMeters = new List<CollectionMeter>();
collectionMeters.Add(new CollectionMeter { Id = 1, Value = 200 });
collectionMeters.Add(new CollectionMeter { Id = 2, Value = 300 });
			
var lastCollectionMeters = 
	(from cm in collectionMeters
	orderby cm.Id
        select cm.Value).FirstOrDefault();
Console.WriteLine(lastCollectionMeters);
Comment 2 Sebastien Pouliot 2012-03-02 09:24:21 UTC
This is already fixed in 5.3 (alpha). I'll look into backporting into the (stable) 5.2.x releases.
Comment 3 danmiser 2012-03-02 09:45:15 UTC
I just did some googling on how to find the stable releases and came up empty. Can you point me to a link on how to download and install them? I'd be happy to install and test once you complete the backport.

Thank you.
Comment 4 Sebastien Pouliot 2012-03-02 10:09:18 UTC
Fixed in 5.2-series 72d981ee9c8777d5ca7bd53712c87d304d5b814a
QA: unit tests added
Comment 5 Sebastien Pouliot 2012-03-02 10:15:05 UTC
Dan, MonoDevelop will warn you when updates are available. By default it does it only for *stable* releases, but 5.3 is *alpha* (untested) so you won't see it. 

You can set MD to alert you for beta or even alpha releases. Look for Updates in MD's preferences.
Comment 6 dmiser 2012-03-03 14:53:05 UTC
Sorry to be a pain. Is there a way to correlate your checkin comment about 5.2-series to a particular stable release? I installed the latest beta last night and the bug still exists.
Comment 7 Sebastien Pouliot 2012-03-03 17:01:52 UTC
> Is there a way to correlate your checkin comment about 5.2-series to a particular stable release?

Not precisely. The purpose of this information is more internal (so we can track changes faster, important if anything goes wrong). Also the comment only means where and when the fix was committed into our source code repository. It's unrelated to when new versions will be tagged, build, tested or released.

What you can assume is that _a_ future (based on the "fixed" comment's date) version of 5.2.x will have the fix. But that's not 100% accurate because:

a) the next 5.2.x stable (e.g. 5.2.6) version could already be ready (built) or in testing (QA). In such case the fix will only be available in a future version (e.g. 5.2.7);

b) the fix could be removed (reverted) if testing shows it introduced new issues (or regressed past issues). In most cases the bug report (like this one) will be re-opened since we included the information (in the comments) to allow us to track it back to the original report.


> I installed the latest beta last night and the bug still exists.

The fix is not available on any _beta_ release. E.g. 5.2.6 is/was beta/release-candidate but it was built a few days before my fix was committed (and even before you reported the bug).

Like I said on comment #2 the fix is, right now, only available on the 5.3 _alpha_ release if you wish to test it.
Comment 8 danmiser 2012-03-03 17:14:40 UTC
Great info. Thank you. I really appreciate how responsive you guys are.