Bug 21048 - mono exits while loading DLL
Summary: mono exits while loading DLL
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.8.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-07-02 11:38 UTC by Jeremy Kolb
Modified: 2014-08-12 15:11 UTC (History)
3 users (show)

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

VS2013 project (4.23 MB, application/octet-stream)
2014-07-02 11:38 UTC, Jeremy Kolb

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 Jeremy Kolb 2014-07-02 11:38:05 UTC
Created attachment 7265 [details]
VS2013 project

Using VS2013

I’m having trouble loading the GeoAPI.Bootstrapper.NetTopologySuite.dll in my Xamarin Android project.  It’s a PCL but when I run through the debugger Mono simply exits.  Sometimes it has an error message about loading the DLL and sometimes not.  If I remove the DLL from the project it works fine

I can’t find any incorrect settings in the PCL so I think it may be a bug in Xamarin?   Regardless I’m hoping that whatever the case is that there’s a better error message for this case.
Comment 1 Jeremy Kolb 2014-07-10 11:41:31 UTC
I still can't get around this.
Comment 2 Mohit Kheterpal 2014-07-11 06:41:50 UTC
I have run the attached project in VS and getting same behavior i.e. with dll GeoAPI.Bootstrapper.NetTopologySuite application exists with error "The program 'Mono' has exited with code 0 (0x0).". However when we remove this dll then it works fine as shown in screencast : http://screencast.com/t/YPaz1Rx9yAq

Error Log : https://gist.github.com/saurabh360/07c54f10c81e11b2b6f6

Environment info :
Microsoft Visual Studio Professional 2012
Version 11.0.61030.00 Update 4
Microsoft .NET Framework
Version 4.5.50938
Installed Version: Professional

Xamarin (f2fbf971100745e8ad580d08c69ef29aa4d566ff)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android
Comment 3 Jeremy Kolb 2014-08-03 16:05:43 UTC
Is there any way to debug this?

08-03 19:31:23.676 D/Mono    ( 1340): Assembly Loader probing location: 'GeoAPI.Bootstrapper.NetTopologySuite'.
In mgmain JNI_OnLoad
08-03 19:31:23.676 F/monodroid-assembly( 1340): Coult not load assembly 'GeoAPI.Bootstrapper.NetTopologySuite' during startup registration.
08-03 19:31:23.676 F/monodroid-assembly( 1340): This might be due to an invalid debug instalation.
08-03 19:31:23.676 F/monodroid-assembly( 1340): A common cause is to 'adb install' the app directly instead of doing from the IDE.
The program 'Mono' has exited with code 0 (0x0).
Comment 4 Jonathan Pryor 2014-08-12 11:52:06 UTC
This sample fails to build on OS X...due to case sensitivity issues:

> error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'GeoAPI.BootStrapper.NetTopologySuite, Version=, Culture=neutral, PublicKeyToken=f580a05016ebada1'. Perhaps it doesn't exist in the Mono for Android profile?
> File name: 'GeoAPI.BootStrapper.NetTopologySuite.dll'
>   at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0 
>   at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in <filename unknown>:0 
>   at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (ICollection`1 assemblies, Mono.Cecil.AssemblyDefinition assembly, Boolean topLevel) [0x00000] in <filename unknown>:0 
>   at Xamarin.Android.Tasks.ResolveAssemblies.Execute () [0x00000] in <filename unknown>:0 

The reason is that GeoAPI.BootStrapper.NetTopologySuite.dll doesn't exist; instead, it's GeoAPI.Bootstrapper.NetTopologySuite.dll (note case difference in 'Boot[Ss]trapper').

Renaming GeoAPI.Bootstrapper.NetTopologySuite.dll to GeoAPI.BootStrapper.NetTopologySuite.dll allows it to compile on OS X.
Comment 5 Jonathan Pryor 2014-08-12 12:22:40 UTC
Once built and installed, it likewise fails for me as it does in Comment #3:

> F/monodroid-assembly(22163): Coult not load assembly 'GeoAPI.Bootstrapper.NetTopologySuite' during startup registration.

but also note the case difference: it's trying to load GeoAPI.Bootstrapper.NetTopologySuite.dll, yet what's actually installed?

> $ adb shell ls -l /storage/sdcard0/Android/data/NtsPclTest.NtsPclTest/files/.__override__
> -rw-rw---- u0_a575  sdcard_r     5632 2014-08-12 11:54 GeoAPI.BootStrapper.NetTopologySuite.dll
> -rw-rw---- u0_a575  sdcard_r    58368 2014-08-12 11:54 GeoAPI.dll
> -rw-rw---- u0_a575  sdcard_r    28160 2014-08-12 11:54 NetTopologySuite.IO.SpatiaLite.dll
> -rw-rw---- u0_a575  sdcard_r   564736 2014-08-12 11:54 NetTopologySuite.dll
> -rw-rw---- u0_a575  sdcard_r     5632 2014-08-12 11:54 NtsPclTest.dll
> -rw-rw---- u0_a575  sdcard_r     1299 2014-08-12 11:54 NtsPclTest.dll.mdb
> -rw-rw---- u0_a575  sdcard_r   187392 2014-08-12 11:54 PowerCollections.dll
> -rw-rw---- u0_a575  sdcard_r    90112 2014-08-12 11:54 ProjNET.dll

What's actually installed is GeoAPI.BootStrapper.NetTopologySuite.dll (because that's what I needed in order to compile).

What we have is a casing mismatch.

The fix is to edit NtsPclTest.csproj and change *all* references of GeoAPI.Bootstrapper.NetTopologySuite to GeoAPI.BootStrapper.NetTopologySuite:

> $ diff -u NtsPclTest.csproj.old NtsPclTest.csproj
> --- NtsPclTest.csproj.old	2014-08-12 12:21:14.000000000 -0400
> +++ NtsPclTest.csproj	2014-08-12 12:21:21.000000000 -0400
> @@ -43,8 +43,8 @@
>      <Reference Include="GeoAPI">
>        <HintPath>..\packages\GeoAPI.1.7.3\lib\portable-net403+sl5+win8+wp8\GeoAPI.dll</HintPath>
>      </Reference>
> -    <Reference Include="GeoAPI.Bootstrapper.NetTopologySuite">
> -      <HintPath>..\packages\NetTopologySuite.1.13.3\lib\portable-net403+sl5+win8+wp8\GeoAPI.Bootstrapper.NetTopologySuite.dll</HintPath>
> +    <Reference Include="GeoAPI.BootStrapper.NetTopologySuite">
> +      <HintPath>..\packages\NetTopologySuite.1.13.3\lib\portable-net403+sl5+win8+wp8\GeoAPI.BootStrapper.NetTopologySuite.dll</HintPath>
>      </Reference>
>      <Reference Include="Mono.Android" />
>      <Reference Include="mscorlib" />

Nuke the bin and obj directories, rebuild+reinstall, and the app Works For Me™.

TL;DR: Android is a case-sensitive platform. You must make sure that all assembly references are consistent with regards to casing.
Comment 6 Jeremy Kolb 2014-08-12 15:11:14 UTC
Ahhhh Thanks!  You're right, that did it.  I should have caught that.