Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an F# library in a C# project in Xamarin

Tags:

c#

xamarin

f#

I have a solution in Xamarin Studio with a C# console program trying to call an F# library.

The reference is fine, everything builds.

My F# code looks like the following:

namespace MyStore.Library

module public Lookup =

    open System

    let lookup name (age:int) =
        String.Format("{0}, {1}", name, age.ToString() );

I can call the F# library from an F# console and a C# library from the C# console, but I can't mix the two.

The C# console doesn't see any F# namespaces at all.

What am I doing wrong?

What should I do to see the F# namespace from C#?

like image 619
Aidan Avatar asked Nov 01 '22 13:11

Aidan


1 Answers

In the C# project, you need to add a reference to your F# project.

In the Solution pane, expand your project, and click the gear icon -> Edit References

Then go to Projects tab, check the F# project you want to reference to, then click OK.

edit referencesprojects

Also, make sure both C# and F# project target to the same .NET framework! To check that, right click a project, Options -> Build -> General

right click projectstarget

like image 162
Ming-Tang Avatar answered Nov 10 '22 12:11

Ming-Tang