Bug 26404 - Incremental Build setting causes Unified app crash during launch: "Library not loaded ... libmonosgen-2.0.dylib"
Summary: Incremental Build setting causes Unified app crash during launch: "Library no...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: XI 8.6.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-01-25 23:44 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-02-19 13:35 UTC (History)
2 users (show)

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


Attachments
Diagnostic build output (114.49 KB, text/plain)
2015-01-25 23:44 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-25 23:44:15 UTC
Created attachment 9491 [details]
Diagnostic build output

Incremental Build setting causes Unified app crash during launch: "Library not loaded ... libmonosgen-2.0.dylib"

The symptoms of this bug are superficially quite similar to bug 23526, but the underlying cause is different. In this case code signing is not the problem because the problem occurs on iOS 7 and iOS 7 does not require codesigned `.dylib` files. Instead the problem is that the build process for Unified API projects does not copy `libmonosgen-2.0.dylib` into the app bundle _at all_.

The results are the same when building via Visual Studio or when building via `xbuild` (or Xamarin Studio) on Mac.


## Regression status: new feature: Unified API


## Steps to reproduce (example for Visual Studio)

1. Create a new "Visual C# -> iOS -> iPhone -> Single View App (iPhone)" app. This will be a Unified API app.

2. Set the Unified Devices menu to select a hardware device connected to the Mac build host.

3. Enable "iOS Build -> General -> Debugging options -> Enable incremental builds" (MtouchFastDev) and save the project properties.

4. Set "iOS Application -> Deployment Target" to "7.0".

5. Attempt to build and run the project on an iOS 7 device.


## Results: the app crashes during launch

From Xcode -> Window -> Devices -> "Device Name" -> View Device Logs [button]

> Dyld Error Message:
>   Library not loaded: @executable_path/libmonosgen-2.0.dylib
>   Referenced from: /var/mobile/Applications/D3E2A463-FF71-451B-B159-1526BF155E10/SingleViewUnified.app/SingleViewUnified
>   Reason: image not found
>   Dyld Version: 324.1


## Results: missing `.dylib` files

The `.app` bundle does not contain all of the expected `.dylib` files

### Unified API app `.dylib` files
> $ (cd UnifiedSingleViewiPhone1.app; ls *.dylib)
> libUnifiedSingleViewiPhone1.exe.dylib
> libXamarin.iOS.dll.dylib
> libmscorlib.dll.dylib

### Classic API app `.dylib` files
> $ (cd ClassicSingleViewiPhone1.app; ls *.dylib)
> libClassicSingleViewiPhone1.exe.dylib
> libmonotouch.dll.dylib
> libmonoboehm-2.0.dylib
> libmscorlib.dll.dylib


Note: the default Classic API template uses the Boehm GC, but switching to sgen works too. When sgen is enabled the Classic API app bundle will contain `libmonosgen-2.0.dylib` as expected.



## Versions

### Windows 8.1 64-bit, in VMWare Fusion 6.0.5 (2209127)

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Xamarin   3.9.274.0 (74260cb)
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Xamarin.iOS   8.6.1.0 (dd1b996f9fab5be032c5bfc54df1bc445953e90f)

### OS X 10.9.5, MacBook Air

Xcode 6.1 (6604), Build 6A1052d

Version: 8.6.1.19 (Business Edition), Hash: 80971a6
Build date: 2015-01-21 17:42:51-0500

Xamarin Studio Version 5.7 (build 661), Hash: b70bab61d
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

Mono 3.12.0 ((detached/a813491)


Also tested: 
Xamarin.iOS 8.6.0.51 (Business Edition), Hash: dfb682f
Build date: 2015-01-08 13:39:32-0500
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-26 00:12:02 UTC
## Workaround

The easiest workaround is simply to disable the incremental build setting.


## Alternate workaround

I'll also mention another workaround because it makes it clear that the missing `libmonosgen-2.0.dylib` really is the main problem:

1. Build a Classic API project for device using the incremental build feature.

2. Copy the `libmonosgen-2.0.dylib` file from the completed Classic API app into the Unified API project, and set its build action to "Content".


The app will now launch successfully on iOS 7 devices. It will still fail on iOS 8 devices (bug 26405).
Comment 2 Rolf Bjarne Kvinge [MSFT] 2015-02-19 13:35:56 UTC
This only happens for 32+64bit apps, selecting either ARM64 or ARMv7[s] as the architecture is another workaround.

In any case we already fixed this internally:

maccore/master: a2d53b9c47dfe8948438ab2da3153b1ad53fafca

QA: unit tests were added as well.