Bug 42434 - Can't use F# PCL in Xamarin Android project, complains about FSharp.Core version
Summary: Can't use F# PCL in Xamarin Android project, complains about FSharp.Core version
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 6.0.99
Hardware: PC Mac OS
: High major
Target Milestone: 7.1 (C9)
Assignee: Jason Imison
Depends on:
Reported: 2016-07-08 18:12 UTC by James Moore
Modified: 2016-09-30 18:49 UTC (History)
8 users (show)

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

Project with fixes applied (60.54 KB, application/zip)
2016-09-30 13:48 UTC, Jason Imison

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 James Moore 2016-07-08 18:12:50 UTC
Create a solution with a Xamarin Android C# project and an F# PCL profile 259 (I think it'll happen with any other profile too).

Attempt to call a method in an F# type that returns an FSharpOption.  You'll get this error:

/Users/james/Projects/Testing15/Testing15/CSC: Error CS1705: Assembly `FSharpPCL, Version=, Culture=neutral, PublicKeyToken=null' depends on `FSharp.Core, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version number than referenced assembly `FSharp.Core, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' (CS1705) (Testing15)

Short screencast at https://knowledge.autodesk.com/community/screencast/be5cfbba-b43b-4f15-86bd-9a96b6f48555
Comment 1 James Moore 2016-07-08 18:13:08 UTC
=== Xamarin Studio Professional ===

Version 6.1 (build 4963)
Installation UUID: 6dc077b1-7f04-4c1c-b481-1dcbb9a8b0a1
	Mono 4.4.0 (mono-4.4.0-branch/fcf7a6d) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000148

=== NuGet ===


=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.Mac ===

Version: (Visual Studio Professional)

=== Xamarin.Android ===

Version: (Visual Studio Professional)
Android SDK: /Users/james/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		6.0.99 (API level 24)

SDK Tools Version: 25.1.7
SDK Platform Tools Version: 24
SDK Build Tools Version: 24

Java SDK: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: (Visual Studio Professional)
Hash: ef65ca5
Branch: master
Build date: 2016-06-07 21:27:36-0400

=== Build Information ===

Release ID: 601004963
Git revision: b37c52e0249c009e308eb144957ac97d1003ec0e
Build date: 2016-06-10 12:00:02-04
Xamarin addins: db4bae9b11a32d16ee009695cd1bfa36455187b0
Build lane: monodevelop-lion-cycle8-preview2

=== Operating System ===

Mac OS X 10.11.5
Darwin retina.restphone.com 15.5.0 Darwin Kernel Version 15.5.0
    Tue Apr 19 18:36:36 PDT 2016
    root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
Comment 2 bryan costanich 2016-07-26 20:44:08 UTC
See https://fsharp.github.io/2015/04/18/fsharp-core-notes.html for more background.

This is a real pain point. Would love to see this fixed as soon as possible.
Comment 3 Jonathan Pryor 2016-07-26 21:25:24 UTC
This should be fixed in Xamarin.Android 6.1.2 ("Cycle 7") and in the next Xamarin.Android alpha release ("Cycle 8"), as those ship FSharp.Core.dll

That said, in the spirit of Bug #41262, we'd *really* prefer to get out of the F# distribution game, in large part because I don't see the need: The F# NuGet package supports Xamarin.Android and it's up-to-date. Anything we distribute will never be as up-to-date as the NuGet package.

Consequently, we should advice developers to reference the NuGet F# package whenever possible.

@Bryan: I'm not sure what exactly you're referencing from that URL, or what should be fixed, or how it should be fixed. :-(
Comment 4 bryan costanich 2016-07-27 20:26:49 UTC
@JonP, per your comment, I agree about shipping it. Why don't we use the nuget reference for F# projects like we do with Xamarin.Forms? 

RE: the URL - that page describes the correct way to link to FSharp.Core. there are some weird things in there, including AutoGenerateBindings=True, etc.
Comment 5 Jason Imison 2016-07-28 21:13:35 UTC
@bryan - I'm going to switch the templates to to use the NuGet package. I just tried it manually and it seems to work fine.
Comment 6 bryan costanich 2016-07-29 00:05:33 UTC
that's great to hear! Can't to get this shipped.
Comment 7 Parmendra Kumar 2016-09-27 18:02:22 UTC
I have checked this issue with latest Master build and I am getting build error. I have follow the screencast video attached in bug description.

Screencast: http://www.screencast.com/t/fP2ngsW88

Error: https://gist.github.com/lal360/58d8a6285eb5c07adf302ab6eab6d60a

EnvironmentInfo: https://gist.github.com/lal360/b116f44162f156b686ac104718af2823

SampleProject: https://www.dropbox.com/s/61gh4b1v597yz6c/Androidcsh55.zip?dl=0

Hence reopen this issue.
Comment 8 Jason Imison 2016-09-30 13:41:43 UTC
@Parmendra - This does work with the following patch.

Notice that I referenced the Profile259 version of FSharp.Core in both projects. Also, the F# dll can't be loaded as a normal project reference - the C# compiler won't understand it - you need to reference the F# dll directly by browsing to it.

diff --git a/Androidcsh55/Androidcsh55/Androidcsh55.csproj b/Androidcsh55/Androidcsh55/Androidcsh55.csproj
old mode 100755
new mode 100644
index 05a3c9c..6c419e9
--- a/Androidcsh55/Androidcsh55/Androidcsh55.csproj
+++ b/Androidcsh55/Androidcsh55/Androidcsh55.csproj
@@ -48,7 +48,12 @@
     <Reference Include="Xamarin.Android.Support.v7.AppCompat">
-    <Reference Include="FSharp.Core" />
+    <Reference Include="FSharp.Core">^M
+      <HintPath>..\packages\FSharp.Core.\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll</HintPath>^M
+    </Reference>^M
+    <Reference Include="Portable33Fsharp">^M
+      <HintPath>..\Portable33Fsharp\bin\Debug\Portable33Fsharp.dll</HintPath>^M
+    </Reference>^M
     <Compile Include="MainActivity.cs" />
@@ -73,11 +78,5 @@
     <Folder Include="Resources\drawable\" />
-  <ItemGroup>
-    <ProjectReference Include="..\Portable33Fsharp\Portable33Fsharp.fsproj">
-      <Project>{762D3FF2-C827-4721-8B84-35917BFD5DC2}</Project>
-      <Name>Portable33Fsharp</Name>
-    </ProjectReference>
-  </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
\ No newline at end of file
diff --git a/Androidcsh55/Androidcsh55/packages.config b/Androidcsh55/Androidcsh55/packages.config
old mode 100755
new mode 100644
diff --git a/Androidcsh55/Portable33Fsharp/Portable33Fsharp.fsproj b/Androidcsh55/Portable33Fsharp/Portable33Fsharp.fsproj
old mode 100755
new mode 100644
index 8e108bc..e685ddf
--- a/Androidcsh55/Portable33Fsharp/Portable33Fsharp.fsproj
+++ b/Androidcsh55/Portable33Fsharp/Portable33Fsharp.fsproj
@@ -30,14 +30,17 @@
+    <Compile Include="AssemblyInfo.fs" />^M
+    <Compile Include="Component1.fs" />^M
+    <Compile Include="Script.fsx" />^M
+  </ItemGroup>^M
+  <ItemGroup>^M
     <Reference Include="FSharp.Core">
-      <HintPath>$(MSBuildExtensionsPath32)\..\Reference Assemblies\Microsoft\FSharp\.NETCore\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
+      <HintPath>..\packages\FSharp.Core.\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll</HintPath>^M
-    <Compile Include="AssemblyInfo.fs" />
-    <Compile Include="Component1.fs" />
-    <Compile Include="Script.fsx" />
+    <None Include="packages.config" />^M
   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.Portable.FSharp.Targets" />
\ No newline at end of file
Comment 9 Jason Imison 2016-09-30 13:48:04 UTC
Created attachment 17829 [details]
Project with fixes applied

I've attached a zip file with the fixes applied. Closing for now, but considering making F# project references from C# work more easily.
Comment 10 Akhilesh kumar 2016-09-30 18:49:38 UTC
Hi Jason,

I have checked this issue with latest master build and attached sample in Comment 9.

If I rebuild the whole solution then I am getting build error: 

/Users/360_macmini/Downloads/Archive (1)/Androidcsh55/MainActivity.cs(44,44): Error CS0246: The type or namespace name `Portable33Fsharp' could not be found. Are you missing an assembly reference? (CS0246) (Androidcsh55)

Screencast: http://www.screencast.com/t/Sey6hWNC4

It seems that when we build/rebuild the solution, it first try to build C# project and then F# PCL project, thats why we are getting this issue.

But if I build F# project(Portable33Fsharp) and then build/run C# project(Androidcsh55), app build and deploy successfully. OR if I just run the solution by Play button then also it build/run and deploy successfully.

Screencast: http://www.screencast.com/t/8FcMJnwc

Could you please let suggest me whether I have to file a new issue for the build error or reopen the same?

As of now I am closing this issue.

Environment info: https://gist.github.com/danish360/3398833aa608df7bef822b4217cf5b7a