0

I am confused about the difference between referencing fsharp.charting.gtk in interactive and compile mode. The following code

#load "FSharp.Charting.Gtk.2.1.0/lib/net45/FSharp.Charting.Gtk.fsx"
open FSharp.Charting;;         
Chart.Line [ for x in 0 .. 10 -> x, x*x ];;

produces a graph as expected in interactive mode with fsharpi, and I can compile it without errors using fsharpc but running it with mono gives the error:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'

I realize that '#load' is for interactive mode, but I have not been able to discover its correct replacement for compile mode. I'm on osx v. 11.5.2 with an Apple M1 chip. Any help would be much appreciated. Thanks.

Jon
  • 163
  • 1
  • 8
  • Have you considered something like Plotly.NET instead? It's got far more charting functionality and is commercially supported. – Phillip Carter Sep 10 '21 at 14:25
  • I'd also recommend using Plotly.NET, but regarding the error - to run an executable with a dependency, you'll need to make sure the dependency (and all other libraries that it transitively depends on) can be discovered by the runtime - typically, they are copied to the same folder as the executable. Do you have those in the output folder? – Tomas Petricek Sep 12 '21 at 23:19

1 Answers1

0

#load is an F# interactive-only directive. It allows you to "load in" another F# script into the current interactive session. You seem to have discovered that paket can generate these load scripts for you, which allow you to include a package into an interactive session.*

To include a package in a compiled assembly, you're going to need to add it as a reference to your project (.fsproj). Since you're using paket, you can add it like this: dotnet paket add FSharp.Charting.Gtk. You won't need the #load directive in the compiled code.

For more information, take a look at the package's NuGet page, which tells you the various ways to add a package to a project.

* Nowadays with F# 5, you don't actually need those paket load scripts anymore in FSI; you can now do: #r: "nuget: FSharp.Charting.Gtk (see How to use nuget install package for F# script without a solution?).

Jwosty
  • 3,497
  • 2
  • 22
  • 50