Skip to content

When run in FSI, FsiEvaluationSession throws exception when evaluating expression #14622

@CosminSontu

Description

@CosminSontu

Issue Description:

Trying to go through Tutorial: Hosted Execution from fsharp.github.io (https://fsharp.github.io/fsharp-compiler-docs/fcs/interactive.html).
Basically trying to start a FsiEvaluationSession and evaluate f# code.

Steps required to reproduce the problem:

  1. Start Repl (either Visual Studio 2022's repl or dotnet fsi has the same outcome)
  2. Send tutorial code snippets to fsi
  3. When the following line is evaluated,
    evalExpression "42 + 1"
    FsiEvaluationSession throws an exception:

> evalExpression "42 + 1";;
FSharp.Compiler.Interactive.Shell+FsiCompilationException: Operation failed. The error text has been printed in the error stream. To return the corresponding FSharpDiagnostic use the EvalInteractionNonThrowing, EvalScriptNonThrowing or EvalExpressionNonThrowing
at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.commitResult[a,b](FSharpChoice`2 res) in D:\a_work\1\s\src\Compiler\Interactive\fsi.fs:line 3418
at FSI_0032.evalExpression(String text)
at <StartupCode$FSI_0033>.$FSI_0033.main@()
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Stopped due to error

when looking at error stream I find the following output:

_> printf "%A" errStream;;

error FS0193: internal error: The thread is already executing the ControlledExecution.Run method._

Expected behavior

Of course the expectation is that FSIEvaluationSession wouldn't throw exception when tutorial is performed
in FSI (Assumption based on the fact that fsi #r directive is used in tutorial code samples).

Otherwise (hopefully not), please add note in the tutorial itself stating fsi is not a supported environment for FsiEvaluationSession.

Actual behavior

when evaluating a code snipet via any FsiEvaluationExpression eval methods, the following exception ends its execution:
error FS0193: internal error: The thread is already executing the ControlledExecution.Run method.

Known workarounds

Compiling the tutorial code samples as F# Console App works fine!
Couldn't find any workaround for successful execution in FSI.

Related information
Using the following reference of F# Compiler Services:
#r "nuget: FSharp.Compiler.Service, 42.7.101"

  • Operating system
    Windows 11
  • .NET Runtime kind (.NET Core, .NET Framework, Mono)
    - fsi;;
    val it: FSharp.Compiler.Interactive.InteractiveSession =
    FSharp.Compiler.Interactive.InteractiveSession
    {CommandLineArgs = [|"C:\Program Files\dotnet\sdk\7.0.102\FSharp\fsi.dll"|];
  • Editing Tools (e.g. Visual Studio Version, Visual Studio)
    Same behavior from both VS F# Interactive window and dotnet fsi

Metadata

Metadata

Assignees

Labels

Area-FSIBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions