Bug 2699 - Specific project crashes on launch in subsequent Release|iPhone builds
Summary: Specific project crashes on launch in subsequent Release|iPhone builds
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-12-30 11:04 UTC by mscoder610
Modified: 2012-04-09 18:26 UTC (History)
2 users (show)

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

Test project reproducing bug (13.14 KB, application/zip)
2011-12-30 11:04 UTC, mscoder610

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 mscoder610 2011-12-30 11:04:05 UTC
Created attachment 1115 [details]
Test project reproducing bug

I'm using:
MonoDevelop 2.8.5
	Mono 2.10.8 (tarball Mon Dec 19 17:43:18 EST 2011)
	GTK 2.24.5
	GTK# (
Apple Developer Tools:
	 Xcode 4.2 (828)
	 Build 4D199
Monotouch: 5.0.4

Steps to reproduce:
1. Open attached project. Change to Release|iPhone build configuration.
2. With an attached iPad, choose Run >> Run. The build should succeed and deploy to the iPad.
3. Run app on iPad (a white screen should show with an alert popup).
4. Change anything in the C# source, then click Run again. (Example: Add then delete whitespace. The build should occur, not immediately say 'Build Successful'), then deploy again.
5. Run the app on the iPad again.

Result: Crash on launch:
Dec 30 09:42:34 unknown UIKitApplication:jitcompilebug1[0x2bd8][5129] <Notice>: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ExecutionEngineException: Attempting to JIT compile method 'MyLibrary.OrientationUtilities:IsLandscapeOrientation (MonoTouch.UIKit.UIInterfaceOrientation)' while running with --aot-only.
Dec 30 09:42:34 unknown UIKitApplication:jitcompilebug1[0x2bd8][5129] <Notice>:   at JITCompileBug1.JITCompileBug1ViewController+TestClass.Test () [0x00000] in <filename unknown>:0 
Dec 30 09:42:34 unknown UIKitApplication:jitcompilebug1[0x2bd8][5129] <Notice>:   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

Workaround: When this happens, the workaround seems to be to do "Rebuild", instead of just "Build" or "Run".
Comment 1 mscoder610 2011-12-30 12:31:59 UTC
Updating title.
After experimenting more, this bug doesn't seem to have anything to do with PreserveAttribute, or how the code created TestClass using reflection.

If you uncomment line 26, and comment out the reflection-based invocation in lines 29-31 (of JITCompileBug1ViewController.cs), you still get the crash. Also applying a PreserveAttribute to OrientationUtilities.IsLandscapeOrientation (or not) doesn't make any difference.
Comment 2 mscoder610 2011-12-30 12:33:39 UTC
Also to clarify step 3, the source change, and the startup project, should be in JITCompileBug1, not MyLibrary.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-04-03 18:08:02 UTC
I've tried this several times now with MonoTouch 5.3 and an iPad3, and it's never crashed for me.

MonoTouch 5.2+ contains a lot of fixes for random issues like these, can you upgrade and try to see if it's still happening to you?
Comment 4 mscoder610 2012-04-04 13:54:25 UTC
I'm still getting a crash with this project. I've updated MonoTouch to the latest version as of last week, I noticed a newer update yesterday but I haven't applied that one yet. But I am on 5.2.10.

	Mono 2.10.8 (tarball Mon Dec 19 17:43:18 EST 2011)
	GTK 2.24.5
	GTK# (
Apple Developer Tools:
	 Xcode 4.2 (828)
	 Build 4D199
Mono for Android not installed
Monotouch: 5.2.10
Build information:
	Release ID: 20806005
	Git revision: 96a2067d048f7e91f9515c869f214243f1926953
	Build date: 2012-02-17 03:31:11+0000

What I did:
- Clean solution, delete bin & obj for both projects
- Build > Run, works this time
- Hit spacebar in JITCompileBug1ViewController.cs and save.
- Build > Run, crashes on launch

The workaround is the same, but I no longer see the stack trace in the Xcode console (I assume because you guys can no longer print to the console in release mode, re: the email that went out about that). But it still crashes on launch:
Apr  4 12:48:12 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:jitcompilebug1[0x729]) Job appears to have crashed: Abort trap: 6
Apr  4 12:48:12 unknown SpringBoard[15] <Warning>: Application 'JITCompileBug1' exited abnormally with signal 6: Abort trap: 6

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib        	0x304d332c 0x304c2000 + 70444
1   libsystem_c.dylib             	0x37974f54 0x37927000 + 319316
2   libsystem_c.dylib             	0x3796dfe4 0x37927000 + 290788
3   JITCompileBug1                	0x00176ea0 mono_handle_native_sigsegv (mini-exceptions.c:2255)
4   JITCompileBug1                	0x001991d4 sigabrt_signal_handler (mini-posix.c:196)
5   libsystem_c.dylib             	0x3797f532 0x37927000 + 361778
6   libsystem_c.dylib             	0x37974f54 0x37927000 + 319316
7   libsystem_c.dylib             	0x3796dfe4 0x37927000 + 290788
8   JITCompileBug1                	0x00251a7c monoeg_g_logv (goutput.c:128)
9   JITCompileBug1                	0x00251ac8 monoeg_assertion_message (goutput.c:152)
10  JITCompileBug1                	0x001606a4 mono_thread_abort (mini.c:2639)
11  JITCompileBug1                	0x00176898 0x1000 + 1530008
12  JITCompileBug1                	0x00176a9c mono_handle_exception (mini-exceptions.c:1835)
13  JITCompileBug1                	0x00197de8 mono_arm_throw_exception (exceptions-arm.c:158)
14  JITCompileBug1                	0x0011660c throw_exception (mscorlib.dll.6.s:113666)
15  JITCompileBug1                	0x00162c6c mono_jit_compile_method (mini.c:5437)
16  JITCompileBug1                	0x0016e404 mono_aot_plt_resolve (aot-runtime.c:3159)
17  JITCompileBug1                	0x00177ad4 mono_aot_plt_trampoline (mini-trampolines.c:770)
18  JITCompileBug1                	0x00116020 generic_trampoline_aot_plt (mscorlib.dll.6.s:113494)
19  JITCompileBug1                	0x00038b48 JITCompileBug1_JITCompileBug1ViewController_ViewDidLoad (JITCompileBug1.exe.6.s:101)
Comment 5 Rolf Bjarne Kvinge [MSFT] 2012-04-09 18:26:54 UTC
Finally I can reproduce it (I failed to reproduce it earlier because I didn't follow the instructions to the letter, sorry about that).

Fixed in master (8870cd3f) and 5.2-series (dc28f386). It will be included in 5.3.3 and hopefully 5.2.11 too (not entirely sure the fix made it yet).