mbraceproject / MBrace.StarterKit

A collection of demos and tutorials for MBrace
http://mbrace.io
57 stars 34 forks source link

Binding error in FSI while trying to start a Thespian cluster (local) #102

Open aggieben opened 1 year ago

aggieben commented 1 year ago

I'm trying to run the 00-hello-world.fsx script (a chunk at a time). So far, the relevant portion is as follows:

#load "ThespianCluster.fsx"

open System
open System.IO
open MBrace.Core
open MBrace.Flow

let cluster = Config.GetCluster()

ThespianCluster.fsx is as follows:

#r "paket: nuget MBrace.Flow ~> 1.6.0-alpha.2 prerelease"
#r "paket: nuget MBrace.Thespian ~> 1.6.0-alpha.2"

namespace global

module Config =

    open MBrace.Core
    open MBrace.Runtime
    open MBrace.Thespian

    // change to alter cluster size
    let private workerCount = 4

    let mutable private thespian = None

    do
        ThespianWorker.LocalExecutable <- (__SOURCE_DIRECTORY__ + "/../../../MBrace.Core/src/MBrace.Thespian.Worker/bin/Debug/net6/mbrace.thespian.worker.exe")

    /// Gets or creates a new Thespian cluster session.
    let GetCluster() =
        match thespian with
        | None ->
            let cluster =
                ThespianCluster.InitOnCurrentMachine(workerCount,
                                                     logger = new ConsoleLogger(),
                                                     logLevel = LogLevel.Info)
            thespian <- Some cluster
        | Some t -> ()
        thespian.Value

    /// Kills the current cluster session
    let KillCluster() =
        match thespian with
        | None -> ()
        | Some t -> t.KillAllWorkers() ; thespian <- None

Note the package versions referenced in this script. I've got an active branch I'm working on in two forks (dev branch in each): https://github.com/aggieben/MBrace.Core https://github.com/aggieben/MBrace.StarterKit

I've published some nupkgs to https://www.myget.org/F/aggieben/api/v3/index.json that were built from my forks; most of the changes revolve around nuget reference updates, and a few net6 migration things. Nothing really substantive is changed.

When I try to execute the foregoing scripts, FSI fails like this: image

The error being: error FS0193: Could not load file or assembly 'System.CodeDom, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

There's no accompanying stack trace, so I'm a bit lost as to why this error fails. The cluster does actually start. After running this, I have 4 console windows like this: image

But the cluster variable isn't bound, so something is happening between the time the cluster starts and the time the code returns back through GetCluster().

FSI has clearly loaded the CodeDom assembly, because I'm able to run open System.CodeDom;; at the prompt with no problem.

Has anyone got any idea what's causing this error?

aggieben commented 1 year ago

I pushed another commit to my MBrace.Core repository (still dev branch) trying to repro this issue with direct references to the MBrace projects instead of paket package references, and the problem reproduces the same way. This time I also use a paket load script to make sure all the dependencies are loaded. The scripts are like this:

ThespianCluster.fsx:

#load "../../.paket/load/net6.0/main.group.fsx"

#r "../../src/MBrace.Core/bin/Debug/net6/MBrace.Core.dll"
#r "../../src/MBrace.Flow/bin/Debug/net6/MBrace.Flow.dll"
#r "../../src/MBrace.Runtime/bin/Debug/net6/MBrace.Runtime.dll"
#r "../../src/MBrace.Thespian/bin/Debug/net6/MBrace.Thespian.dll"

namespace global

module Config =

    open MBrace.Core
    open MBrace.Runtime
    open MBrace.Thespian

    // change to alter cluster size
    let private workerCount = 4

    let mutable private thespian = None

    do
        ThespianWorker.LocalExecutable <- (__SOURCE_DIRECTORY__ + "/../../src/MBrace.Thespian.Worker/bin/Debug/net6/mbrace.thespian.worker.exe")

    /// Gets or creates a new Thespian cluster session.
    let GetCluster() =
        match thespian with
        | None ->
            let cluster =
                ThespianCluster.InitOnCurrentMachine(workerCount,
                                                     logger = new ConsoleLogger(),
                                                     logLevel = LogLevel.Info)
            printfn "got cluster: %A" cluster
            thespian <- Some cluster
        | Some t -> ()
        thespian.Value

    /// Kills the current cluster session
    let KillCluster() =
        match thespian with
        | None -> ()
        | Some t -> t.KillAllWorkers() ; thespian <- None

and `00-hello-world.fsx``:

#load "ThespianCluster.fsx"

let cluster = Config.GetCluster()
aggieben commented 1 year ago

This issue seems to bear a resemblance to https://github.com/dotnet/fsharp/issues/13126. Unsure if they're related or not.

This one, too: https://github.com/dotnet/fsharp/issues/12703