FSI: error FS0193: internal error: Could not load type '<X>' from assembly

I have this code:

let maximumResidual = 50.0m

let calculateResidual balance = if balance < maximumResidual then balance else maximumResidual

type BasicAccountDetails =
    { Balance: decimal }

type JointAccount =
    { Primary: string
      Secondary: string
      Balance: decimal }

type PersonalAccount =
    { Name: string
      Balance: decimal }
    member this.makeJointWith (addition: PersonalAccount) =
        let thisResidual = calculateResidual this.Balance
        let additionResidual = calculateResidual addition.Balance
        ( { Primary = this.Name
            Secondary = addition.Name
            Balance = (this.Balance - thisResidual) + (addition.Balance - additionResidual) } ,
          { this with Balance = thisResidual },
          { addition with Balance = additionResidual } )

type Account =
    | Personal of PersonalAccount
    | Joint of JointAccount

let janesAccount = Personal { Name = "Jane"; Balance = 200.0m }
let bobsAccount = Personal { Name = "Bob"; Balance = 40.0m }
let maryAndAbesAccount = Joint { Primary = "Mary"; Secondary = "Abe"; Balance = 230.0m }

let accounts : Account list = [ janesAccount; bobsAccount; maryAndAbesAccount ]

let makeJointAccount account1 account2 = 
    match account1, account2 with
        | Personal personal1, Personal personal2 -> Ok <| personal1.makeJointWith personal2
        | Joint _, _ 
        | _, Joint _ -> Error <| "cannot make a joint account from a joint account"

let result = makeJointAccount janesAccount bobsAccount

When I select it all and execute it in the FSI I get the error:

error FS0193: internal error: Could not load type 'PersonalAccount' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

However, when I execute all of the code except the last line in the FSI, and then, separately, execute the last line, it works:

val result: Result<(JointAccount * PersonalAccount * PersonalAccount),string>
= Ok ({ Primary = "Jane"
        Secondary = "Bob"
        Balance = 150.0M }, { Name = "Jane"
                              Balance = 50.0M }, { Name = "Bob"
                                                   Balance = 40.0M })

Is there something I am doing wrong?

I had a little look around the web and found these seemingly-related questions:

…but both are over five years old and those problems seem to be related to structs, which I’m not using.

FSI reports the version as:
Microsoft (R) F# Interactive version 12.0.1.0 for F# 6.0

1 Like

I’m getting the same error if I select all the code and send to FSI. It looks like a compiler bug.

However, if I select it in 3 separate parts and send each to FSI then it runs correctly :thinking:

I managed to whittle this down to a very small sample that produces the same error:

type A = A
type B = B
let x : Result<_, unit> = Ok (A, B)
// error FS0193: internal error: Could not load type 'B' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
// if the name x is replaced with _ then there is no error

Replacing the tuple with an anonymous record gives the same error:

type A = A
type B = B
let x : Result<_, unit> = Ok {| A = A; B = B |}

Seems to be something to do with the result type containing multiple user types.

I’ve reported the issue here: FS0193 internal error when defining two types and putting their values into a Result in one send to FSI · Issue #13107 · dotnet/fsharp · GitHub

1 Like

Many thanks for looking into this.

I had hoped that the problem was not in my code and it seems that it’s probably not, so that’s good to know.
I know what the ‘workaround’ is now – execute the code sequentially in parts – and that’s not too much of a hardship.

Also, thanks for raising the issue on GitHub.
You have probably saved me the trouble of having to answer lots of questions that I would not understand.

Cheers.

1 Like