Bug 51000 - Xamarin Forms references the wrong version of mscorlib (FSharp.Core)
Summary: Xamarin Forms references the wrong version of mscorlib (FSharp.Core)
Status: RESOLVED DUPLICATE of bug 43915
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/SpiegelSoft/Astrid
Depends on:
Blocks:
 
Reported: 2016-12-28 11:11 UTC by Rob Lyndon
Modified: 2017-01-11 19:48 UTC (History)
3 users (show)

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

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 DUPLICATE of bug 43915

Description Rob Lyndon 2016-12-28 11:11:35 UTC
Create a new blank solution in Visual Studio 2015.

Add a new Blank App (Android) under the F# menu.

Add the Xamarin.Forms NuGet package, Version 2.3.3.175.

The following warning message appears as a popover in `MainActivity.fs`:

> The referenced or default base CLI library 'mscorlib' is
> binary-incompatible with the referenced F# core library 'C:\...\packages\Xamarin.Forms.2.3.3.175\lib\MonoAndroid10\FormsViewGroup.dll'. Consider recompiling
> the library or making an explicit reference to a version of this
> library that matches the CLI version you are using.

Later, when I try to instantiate a viewmodel (using ReactiveUI as my MVVM provider), I get this runtime error:

System.MissingMethodException: Method 'Microsoft.FSharp.Quotations.FSharpExpr.Deserialize40' not found.

This usually happens because the wrong version of `FSharp.Core` is being referenced.

This is reproduced in the open source library https://github.com/SpiegelSoft/Astrid
Comment 1 Jason Imison 2016-12-29 17:20:19 UTC
I looked into this a while back.

The warning is because FormsViewGroup.dll has been compiled against mscorlib 4.0.0 which is verifiable with 
```
17:13 $ ikdasm FormsViewGroup.dll | head

// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern Mono.Android
{
  .publickeytoken = (84 E0 4F F9 CF B7 90 65 )                         // ..O....e
```

but Android needs mscorlib 2.0.5.0

The F# compiler guards against this
```
elif not(isfslib) && ((v1 = 4us) && (mscorlibMajorVersion < 4)) then
                    warning(Error(FSComp.SR.buildMscorlibAndReferencedAssemblyMismatch(filename),m))
```

but it seems like the C# compiler doesn't warn about this condition
Comment 2 Rob Lyndon 2016-12-30 11:26:06 UTC
Thanks Jason.

So it's possible that the warning is a red herring.

I'm away until after the New Year, but the runtime error should be easily reproducible from the Astrid repository.
Comment 3 Rob Lyndon 2017-01-08 14:16:26 UTC
Here is the partial debug output:
01-08 14:06:51.722 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Linq.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Linq.dll.so" not found
01-08 14:06:51.722 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Linq.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Linq.dll.so" not found
01-08 14:06:51.722 D/Mono    ( 1520): Assembly Ref addref System.Reactive.Linq[0xb951ff40] -> System.Linq[0xb953b0b0]: 4
01-08 14:06:51.738 D/Mono    ( 1520): Assembly Ref addref System.Runtime[0xb952f6e0] -> System.Core[0xb968d5f0]: 9
01-08 14:06:51.738 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Threading.Tasks.dll'.
01-08 14:06:51.738 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Threading.Tasks.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Threading.Tasks.dll.so" not found
01-08 14:06:51.738 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Threading.Tasks.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Threading.Tasks.dll.so" not found
01-08 14:06:51.738 D/Mono    ( 1520): Assembly Ref addref System.Reactive.Linq[0xb951ff40] -> System.Threading.Tasks[0xb9533e30]: 4
01-08 14:06:51.738 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Threading.dll'.
01-08 14:06:51.738 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Threading.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Threading.dll.so" not found
01-08 14:06:51.738 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Threading.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Threading.dll.so" not found
01-08 14:06:51.738 D/Mono    ( 1520): Assembly Ref addref System.Reactive.Linq[0xb951ff40] -> System.Threading[0xb95377b0]: 6
01-08 14:06:51.750 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Reflection.dll'.
01-08 14:06:51.754 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Reflection.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Reflection.dll.so" not found
01-08 14:06:51.754 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Reflection.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Reflection.dll.so" not found
01-08 14:06:51.754 D/Mono    ( 1520): Assembly Ref addref System.Reactive.Core[0xb951e2c0] -> System.Reflection[0xb9535b30]: 5
01-08 14:06:51.754 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Reflection.dll'.
01-08 14:06:51.754 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Reflection.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Reflection.dll.so" not found
01-08 14:06:51.754 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Reflection.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Reflection.dll.so" not found
01-08 14:06:51.754 D/Mono    ( 1520): Assembly Ref addref System.Reactive.PlatformServices[0xb9520dd0] -> System.Reflection[0xb9535b30]: 6
01-08 14:06:51.754 D/Mono    ( 1520): Assembly Ref addref System.Reactive.PlatformServices[0xb9520dd0] -> System.Reactive.Linq[0xb951ff40]: 3
01-08 14:06:51.754 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Diagnostics.Debug.dll'.
01-08 14:06:51.754 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Diagnostics.Debug.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Diagnostics.Debug.dll.so" not found
01-08 14:06:51.754 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Diagnostics.Debug.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Diagnostics.Debug.dll.so" not found
01-08 14:06:51.754 D/Mono    ( 1520): Assembly Ref addref System.Reactive.PlatformServices[0xb9520dd0] -> System.Diagnostics.Debug[0xb9531390]: 3
01-08 14:06:51.758 D/Mono    ( 1520): Assembly Loader probing location: '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/gac/System.Reactive.Debugger/2.2.5.0__31bf3856ad364e35/System.Reactive.Debugger.dll'.
01-08 14:06:51.758 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Reactive.Debugger.dll'.
01-08 14:06:51.758 D/Mono    ( 1520): Assembly Loader probing location: '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/System.Reactive.Debugger.dll'.
01-08 14:06:51.758 D/Mono    ( 1520): Assembly Loader probing location: '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/gac/System.Reactive.Debugger/2.2.5.0__31bf3856ad364e35/System.Reactive.Debugger.exe'.
01-08 14:06:51.758 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Reactive.Debugger.exe'.
01-08 14:06:51.758 D/Mono    ( 1520): Assembly Loader probing location: '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/System.Reactive.Debugger.exe'.
01-08 14:06:51.774 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Runtime.Extensions.dll'.
01-08 14:06:51.774 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Runtime.Extensions.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Runtime.Extensions.dll.so" not found
01-08 14:06:51.774 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Runtime.Extensions.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Runtime.Extensions.dll.so" not found
01-08 14:06:51.774 D/Mono    ( 1520): Assembly Ref addref System.Reactive.Core[0xb951e2c0] -> System.Runtime.Extensions[0xb9539460]: 3
01-08 14:06:51.782 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Globalization.dll'.
01-08 14:06:51.782 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Globalization.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Globalization.dll.so" not found
01-08 14:06:51.782 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Globalization.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Globalization.dll.so" not found
01-08 14:06:51.782 D/Mono    ( 1520): Assembly Ref addref System.Reactive.Core[0xb951e2c0] -> System.Globalization[0xb953a270]: 3
01-08 14:06:51.878 D/Mono    ( 1520): Assembly Ref addref Astrid.Mobile.Shared[0xb9519760] -> Xamarin.Forms.Core[0xb9529cf0]: 6
01-08 14:06:51.878 D/Mono    ( 1520): Assembly Loader probing location: '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Diagnostics.Debug.dll'.
01-08 14:06:51.878 D/Mono    ( 1520): AOT module '/storage/emulated/0/Android/data/Astrid.Mobile.Droid.Astrid.Mobile.Droid/files/.__override__/System.Diagnostics.Debug.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Diagnostics.Debug.dll.so" not found
01-08 14:06:51.878 D/Mono    ( 1520): AOT module '/Users/builder/data/lanes/3511/501e63ce/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Diagnostics.Debug.dll.so' not found: dlopen failed: library "/data/app-lib/Astrid.Mobile.Droid.Astrid.Mobile.Droid-1/libaot-System.Diagnostics.Debug.dll.so" not found
01-08 14:06:51.878 D/Mono    ( 1520): Assembly Ref addref Xamarin.Forms.FSharp[0xb952aca0] -> System.Diagnostics.Debug[0xb9531390]: 4
01-08 14:06:51.890 D/Mono    ( 1520): Assembly Ref addref Xamarin.Forms.Platform.Android[0xb952bb30] -> Xamarin.Android.Support.v4[0xb9524700]: 2
01-08 14:06:51.902 I/dalvikvm( 1520): Could not find method android.view.ViewGroup.<init>, referenced from method md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.<init>
01-08 14:06:51.902 W/dalvikvm( 1520): VFY: unable to resolve direct method 20620: Landroid/view/ViewGroup;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;II)V
01-08 14:06:51.902 D/dalvikvm( 1520): VFY: replacing opcode 0x70 at 0x0000
Unhandled Exception:

System.MissingMethodException: Method 'Microsoft.FSharp.Quotations.FSharpExpr.Deserialize40' not found.

Error while resolving expression: Specified argument was out of the range of valid values.
Thread finished: <Thread Pool> #4
01-08 14:06:57.582 D/Mono    ( 1520): [0xb997db60] worker finishing
The thread 'Unknown' (0x4) has exited with code 0 (0x0).
In mgmain JNI_OnLoad
Comment 4 Rob Lyndon 2017-01-08 14:47:51 UTC
And the stack trace:

  at Astrid.Mobile.Shared.DashboardViewModel..ctor (Microsoft.FSharp.Core.FSharpOption`1[T] host) [0x00000] in C:\Users\Rob Lyndon\Documents\GitHub\Astrid\Astrid.Mobile.Shared\ViewModels.fs:10 
  at Astrid.Mobile.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00038] in C:\Users\Rob Lyndon\Documents\GitHub\Astrid\Astrid.Mobile.Droid\MainActivity.fs:34 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/3511/501e63ce/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.App.Activity.cs:2550 
  at (wrapper dynamic-method) System.Object:b673e62f-ece2-4dd0-9655-083f7eab1a00 (intptr,intptr,intptr)
Comment 5 Rob Lyndon 2017-01-08 23:33:18 UTC
I've been investigating this issue this weekend.

The FSharp.Core version that is loaded is stuck on the obsolete version 2.3.98.1. This corresponds to the FSharp.Core.dll file in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0.

I have tried to remove this version and load the NuGet package FSharp.Core; however, when I build the Android project, the path always reverts to the obsolete file in the Reference Assemblies path.
Comment 6 Rob Lyndon 2017-01-10 00:03:19 UTC
Looking through the GitHub repository, it appears that this was fixed by the fix for https://bugzilla.xamarin.com/show_bug.cgi?id=43915, which I don't have access to.

Would it be possible to confirm that this is the case?

https://github.com/xamarin/xamarin-android/commit/df41af046000556ed82f638e8041b7f718966a92
Comment 7 Jason Imison 2017-01-10 00:08:03 UTC
Hi Rob... I'm pretty snowed under right now as we have a deadline looming.

There is some information on #43915 that might help you though.

```
So it looks like Nuget is trying to be smart. Its not adding the hint path automatically because there is a Framework assembly available. 

So it looks like the options are.

1) Have the user add the HintPath manually. 
2) Remove the FSharp.Core from the MonoAndroid/v1.0 directory.

Option 2 would require users still using the old FSharp to add the old nuget package to get their projects to compile.
```

also - 
```
Looks like this is a known bug in the F# project system. See https://github.com/NuGet/Home/issues/3443#issuecomment-247128883
```
Comment 8 Jason Imison 2017-01-10 00:12:13 UTC
Also, this

OK I have replicated this issue. 

It comes down to Nuget on Windows. Under Xamarin Studio on Mac when you add the FSharp.Core Nuget package it adds a reference to the correct mobile platform and adds a HintPath to the reference like so 

<Reference Include="FSharp.Core">
      <HintPath>packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll</HintPath>
    </Reference>

This tells the build system to look for FSharp.Core in the nuget package directory. 

Under Visual Studio this hint path is NOT added to the reference. As a result the system ALWAYS picks up the System provided FSharp.Core which is the older version. Hence the error. 

Adding the correct HintPath to the project file seems to fix the issue. But why does Nuget NOT add the hint path in the first place is the real question here.
Comment 9 Rob Lyndon 2017-01-10 09:48:35 UTC
Thanks Jason. The HintPath reference works. I'll add this to the StackOverflow answer and mark this bug as a duplicate.
Comment 10 Rob Lyndon 2017-01-10 22:22:41 UTC
I can't mark it as a duplicate, as I don't have access to #43915, but I'm happy for this issue to be closed.
Comment 11 Jason Imison 2017-01-11 19:48:05 UTC

*** This bug has been marked as a duplicate of bug 43915 ***