Search code examples
iosxamarin.iosmonovisual-studio-mac

Xamarin.iOS app crashes on missing Mono runtime; no suitable image found; code signing blocked mmap


I'm trying to build a Xamarin Forms app with an associated App Extension for iOS. My solution structure is like this:

MyProject
  \BitThicket.MyProject                    -- Forms project
  \BitThicket.MyProject.Core               -- NET Standard 2.0 class library
  \BitThicket.MyProject.iOS                -- iOS project
  \BitThicket.MyProject.Extensions.Intents -- Intents project

Each project was created from a template, and I've made few changes - and the crash happens at startup, so none of my code is reached anyway.

I'm targeting iOS 11.1, and I have a valid signing certificate and provisioning profile set up. I'm able to build the app and deploy it to a device (my iPhone 7+) from Visual Studio for Mac (7.2.2). However, when the debugger tries to launch the app for me, the blank splash view shows and then the app crashes. The debugger never connects. Incidentally, it crashes in the same way when the app is launched manually on the device.

I retrieved the device logs using Xcode, and the crash looks like this:

Incident Identifier: 948709A2-74AA-4E16-BEEA-072CFCF4AB38
CrashReporter Key:   ######################################
Hardware Model:      iPhone9,2
Process:             BitThicket.Turns.iOS [2457]
Path:                /private/var/containers/Bundle/Application/#####-##############-############/BitThicket.Turns.iOS.app/BitThicket.Turns.iOS
Identifier:          com.bitthicket.Turns
Version:             1.0 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.bitthicket.Turns [818]


Date/Time:           2017-11-24 09:41:15.3743 -0600
Launch Time:         2017-11-24 09:41:15.3041 -0600
OS Version:          iPhone OS 11.1.2 (15B202)
Baseband Version:    3.21.01
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Description: DYLD, Library not loaded: @rpath/Mono.framework/Mono | Referenced from: /var/containers/Bundle/Application/########-####-####-####-############/BitThicket.Turns.iOS.app/BitThicket.Turns.iOS | Reason: no suitable image found.  Did find: | /private/var/containers/Bundle/Application/########-####-####-####-############/BitThicket.Turns.iOS.app/Frameworks/Mono.framework/Mono: code signing blocked mmap() of '/private/var/containers/Bundle/Application/########-####-####-####-############/BitThicket.Turns.iOS.app/Frameworks/Mono.framework/Mono'
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 Crashed:
0   dyld                            0x0000000106722f1c __abort_with_payload + 8
1   dyld                            0x00000001067226f4 abort_with_payload_wrapper_internal + 100
2   dyld                            0x0000000106722720 fcntl + 0
3   dyld                            0x00000001066f8498 dyld::fastBindLazySymbol+ 17560 (ImageLoader**, unsigned long) + 0
4   dyld                            0x00000001066fb714 dyld::_main+ 30484 (macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 7376
5   dyld                            0x00000001066f521c _dyld_start + 68

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000006   x1: 0x0000000000000001   x2: 0x000000016d50a470   x3: 0x00000000000000a5
    x4: 0x000000016d50a070   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x00000000000002f0
    x8: 0x0000000000000020   x9: 0x0000000000000009  x10: 0x6f6e6f4d2f736b72  x11: 0x6f77656d6172662e
   x12: 0x726f77656d617246  x13: 0x2e6f6e6f4d2f736b  x14: 0x726f77656d617266  x15: 0x00276f6e6f4d2f6b
   x16: 0x0000000000000209  x17: 0x000000008000001f  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x000000016d50a070  x21: 0x00000000000000a5  x22: 0x000000016d50a470  x23: 0x0000000000000001
   x24: 0x0000000000000006  x25: 0x00000001028f4000  x26: 0x0000000106736000  x27: 0x0000000106735f88
   x28: 0x000000016d50ba70   fp: 0x000000016d50a040   lr: 0x00000001067226f4
    sp: 0x000000016d50a000   pc: 0x0000000106722f1c cpsr: 0x00000000

Binary Images:
0x1028f4000 - 0x103e43fff BitThicket.Turns.iOS arm64  <###########################> /var/containers/Bundle/Application/########-####-####-####-############/BitThicket.Turns.iOS.app/BitThicket.Turns.iOS
0x1066f4000 - 0x106733fff dyld arm64  <##########################> /usr/lib/dyld

EOF

Does anyone know what causes this? There don't seem to be a lot of direct answers on the Xamarin forums or other places (including SO, unfortunately). I've tried some of the simple things, like restarting Visual Studio for Mac, or delete the app from my device and clean/rebuild the solution, but those things don't seem to help.

In the termination description it sounds like it tried to load mono, but mmap was blocked by code signing somehow - but I don't really understand how. The app builds and deploys to my device, so it seems like code signing is working.


Solution

  • After digging a little further, I found a few examples of problems that seemed similar, and the most common approach factor seemed to be that signing certificates were incorrectly configured. I'm still curious about the underlying reason - the "why" behind the why.

    In the end, I found that I had the "Apple Worldwide Developer Relations Certificate Authority" on both the "System" and "login" keychains, as well as configured for "Always Trust", when it should have been only in my "login" keychain and configured for "System Defaults".

    Once I corrected those issues, I tried again and I still had the problem. It finally went away after rebooting my mac.