Bug 42986 - Using FSharp with Xamarin is currently not possible under Windows.
Summary: Using FSharp with Xamarin is currently not possible under Windows.
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 6.1.0 (C7)
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2016-08-02 09:39 UTC by Romain Flechner
Modified: 2017-10-04 15:32 UTC (History)
5 users (show)

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


Attachments
repro attempt (15.96 KB, application/zip)
2016-08-03 16:32 UTC, Peter Collins
Details
failing test case (16.90 KB, application/zip)
2016-08-04 13:09 UTC, Peter Collins
Details

Description Romain Flechner 2016-08-02 09:39:20 UTC
Hi,

I need to use FSharp 4 , so I installed the nuget FSharp.Core v4.0.0.1 .
Then I have the problem mentionned here: http://forums.xamarin.com/discussion/comment/212937
MSBuild seems to be using an incorrect .Net Framework version.
So in "General Settings", I unckeched "Use MSBuild ...".

In the build log we can see that XBuild is called with: 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\FSharp.Core.dll"

A workaround could be replacing FSharp DLLs in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\ by DLLs extracted in ./packages .
It's compiling !

Now I plug my phone on my computer and it try to deploy my app on it (hoping to finally debug) ...
BUT, no APK is generated by XBuild and deploying on devices doesn't work ...
Comment 1 Prashant Cholachagudda 2016-08-03 06:39:16 UTC
# Steps to reproduce
1. Create a Xamarin.Forms app with F#
2. Install FSharp.Core v4.0.0.1 from Nuget
3. Build the project

# Version information

Xamarin Studio Enterprise
Version 6.1 (build 5271)
Installation UUID: cd0fe011-1678-4f41-b504-7e5ecff01e29
Runtime:
 Microsoft .NET 4.0.30319.42000
 GTK+ 2.24.26 (Dark theme)
 GTK# 2.12.38

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Xamarin.Android
Version: 6.2.0.15 (Xamarin Enterprise)
Android SDK: C:\Program Files (x86)\Android\android-sdk
 Supported Android versions:
 4.0.3 (API level 15)
 4.4 (API level 19)
 5.0 (API level 21)
 5.1 (API level 22)
 6.0 (API level 23)

SDK Tools Version: 25.1.2
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_55
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) Client VM (build 24.55-b03, mixed mode, sharing)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin Android Player
Not Installed

Build Information
Release ID: 601005271
Git revision: ccf5113663592764e282a0388cedd63d11b28107
Build date: 2016-07-26 15:35:58-04
Xamarin addins: 8d105bffe3a76f192eec36b6df0929d92806791c
Build lane: monodevelop-windows-cycle8

Operating System
Windows 10.0.10586.0 (64-bit)
Comment 2 Peter Collins 2016-08-03 16:32:11 UTC
Created attachment 16878 [details]
repro attempt

This scenario works for me. I'm able to build and deploy the attached project using the latest Alpha builds XA 6.2.0.23 with XS 6.1 (5298) on Windows. You'll need to add the FSharp.Core NuGet to the Forms library project as shown in the repro I've attached.

Are you able to reproduce with the attached project? Am I missing a step?
Comment 3 Romain Flechner 2016-08-04 08:57:57 UTC
Hi,


You added FSharp.Core NuGet only in the PCL project.

In my case, I want to use FSharp 4 in Android project too.

Try to compile with:

1 - In PCL:

namespace Forms42986

open Xamarin.Forms

type App() =
    inherit Application()

    let stack = StackLayout(VerticalOptions = LayoutOptions.Center)
    let label = Label(XAlign = TextAlignment.Center, Text = "Welcome to F# Xamarin.Forms!")
    do
        stack.Children.Add(label)
        base.MainPage <- ContentPage(Content = stack)
        let text = "coucou"
        if isNull text
        then ()

2 - In Android:

namespace Forms42986.Droid
open System;

open Android.App;
open Android.Content;
open Android.Content.PM;
open Android.Runtime;
open Android.Views;
open Android.Widget;
open Android.OS;

[<Activity (Label = "Forms42986.Droid", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = (ConfigChanges.ScreenSize ||| ConfigChanges.Orientation))>]
type MainActivity() =
    inherit Xamarin.Forms.Platform.Android.FormsApplicationActivity()
    override this.OnCreate (bundle: Bundle) =
        base.OnCreate (bundle)

        Xamarin.Forms.Forms.Init (this, bundle)

        this.LoadApplication (new Forms42986.App ())

        let text = "coucou"
        if isNull text
        then ()


I tested on 3 computers, it always failed.

Regards
Comment 4 Peter Collins 2016-08-04 13:09:40 UTC
Created attachment 16897 [details]
failing test case

Oh my mistake, thanks for the info. I've updated the test case which now fails with the following. I am also able to reproduce the same failure with this project on Mac.

> FSC : error FS0219: The referenced or default base CLI library 'mscorlib' is binary-incompatible with the referenced F# core library 'C:\Users\xamarinqa\Desktop\Forms42986\packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll'. Consider recompiling the library or making an explicit reference to a version of this library that matches the CLI version you are using.
> FSC : error FS0218: Unable to read assembly 'C:\Users\xamarinqa\Desktop\Forms42986\packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll'
Diagnostic build output:
https://gist.github.com/pjcollins/bb38ae230e6090985cfa1bcb7ca3c79a

@Romain are these the same errors you're seeing?
Comment 5 Romain Flechner 2016-08-04 13:15:02 UTC
Yes I have:


FSC : error FS0219: The referenced or default base CLI library 'mscorlib' is binary-incompatible with the referenced F# core library 'D:\prog\Forms42986\packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll'. Consider recompiling the library or making an explicit reference to a version of this library that matches the CLI version you are using.

FSC : error FS0218: Unable to read assembly 'D:\prog\Forms42986\packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll'


Thank you very much for your help
Comment 6 Peter Collins 2016-08-04 14:16:27 UTC
If you add a reference to mscorlib in your `*Droid.fsproj` does that resolve the issue?
>     <Reference Include="mscorlib" />
Comment 7 Romain Flechner 2016-08-04 14:22:00 UTC
Yes, it works.

Thanks.
Comment 8 Jason Imison 2016-10-06 12:23:10 UTC
I was going to update the templates to do this but I get 2 warnings :-

FSC:  warning FS0217: The referenced or default base CLI library 'mscorlib' is binary-incompatible with the referenced library '/Users/jason/Projects/bug42986/Droid/../packages/Xamarin.Forms.2.3.1.114/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.
FSC:  warning FS0217: The referenced or default base CLI library 'mscorlib' is binary-incompatible with the referenced library '/Users/jason/Projects/bug42986/bug42986/bin/Debug//bug42986.dll'. Consider recompiling the library or making an explicit reference to a version of this library that matches the CLI version you are using.

The app works fine when deployed on Android (all requests for mscorlib are redirected to use version 2.0.5.0) but the F# compiler complains. The C# compiler seems to just ignore this scenario.

So not sure what to do about this. I could add a `--nowarn FS2017` as the warning seems innocuous, but then that would mask potential genuine errors.
Comment 9 Jason Imison 2016-10-06 12:27:30 UTC
Uploaded test project here https://github.com/nosami/bug42986
Comment 10 Jon Douglas [MSFT] 2017-10-04 15:32:39 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.

Note You need to log in before you can comment on or make changes to this bug.