I am unable to reference FSharpOption<>
within my C# PCL project targeting Xamarin.Android within Visual Studio 2015.
Here's a video that shows the steps of me attempting to resolve it.
The error I receive is the following:
The type
FSharpOption<>
is defined in an assembly that is not referenced. You must add a reference to assembly
FSharp.Core, Version=3.7.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
NOTE:
My C# project DOES reference FSharp.Core. It is referencing the same FSharp.Core version that my F# projects are using:
some_path\packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll
Adding an App Config
The app.config file that I placed in my Android client project is the same app.config file that I am using in my test project that's written in F#.
The app.config is the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Can anyone provide me guidance on the steps required to reference FSharp.Core functionality within my C# project?
UPDATED
I have another class that successfully references FSharp.Core within the same C# project:
static class Utility
{
public static bool IsSome(this FSharpOption<string> option) => FSharpOption<string>.get_IsSome(option);
public static bool IsNone(this FSharpOption<string> option) => FSharpOption<string>.get_IsNone(option);
}
The code above does not appear to cause any compile errors. Again, this file is in the same project as my other file that does cause errors.
The code that causes errors is the following:
using Microsoft.FSharp.Core;
// . . .
if (_viewModel.FamilySummary.IsSome()) {
}
NOTE:
The using
statement for FSharp.Core appears to be ignored.
My viewmodel is hosted within an F# project inside Visual Studio.
When I run into similar issue the solution was to uninstall FSharp.Core from both projects (the C# and the F# one) and then install it again but using the NuGet package manager for the Solution (not individually for each project).
So after removing FSharp.Core from both go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution...
There search for FSharp.Core, tick all the projects you want to add the library to and select the version you want to add.
That solved this issue for me.
Edit: The other thing worth checking is that any library that is using FSharp.Core is actually using the same version as the one you installed.
After changing binding redirects in app.config
, you may also need to delete the obj
folder under the executable project folder.
For some reason an outdated config file can hang around in there and get copied to your bin folders, despite performing clean rebuilds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With