Skip to content

[Regression] [multiemit] FsiEvaluationSession can't find method in hosting assembly #13197

@brettfo

Description

@brettfo

A console app that uses FsiEvaluationSession can't execute a method defined in the console app. The behavior worked in FSharp.Compiler.Service version 41.0.2 and started to fail in version 41.0.3. I've traced the failure back to commit 45518d2 from #12722.

Full repro. N.b., the repro as given here passes and shows the output of

value: "3"

and if you simply update the FSharp.Compiler.Service package version to 41.0.3 then the output becomes:

exception: System.MissingMethodException: Method not found: 'System.Int32 FSharpMissingMethod.MyModule.add(System.Int32, System.Int32)'.
   at <StartupCode$FSI_0001>.$FSI_0001.main@()

Project.fsproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="MyModule.fs" />
    <Compile Include="Program.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FSharp.Compiler.Service" Version="41.0.2" />
  </ItemGroup>

</Project>

MyModule.fs:

namespace FSharpMissingMethod

type Sentinel () =
    let x = ()

module MyModule =
    let add a b = a + b

Program.fs:

module Main

open FSharp.Compiler.Interactive.Shell
open System.IO
open System.Threading

[<EntryPoint>]
let main args =

    let config = FsiEvaluationSession.GetDefaultConfiguration()
    let argv = [|
        typeof<FSharpMissingMethod.Sentinel>.Assembly.Location
        "--noninteractive"
        "--targetprofile:netcore"
        "--langversion:preview"
        "/usesdkrefs-"
        |]
    let fsi = FsiEvaluationSession.Create(config, argv, TextReader.Null, TextWriter.Null, TextWriter.Null)
    let assemblyPath = typeof<FSharpMissingMethod.Sentinel>.Assembly.Location.Replace("\\", "/")
    let code = $@"
#r ""{assemblyPath}""
FSharpMissingMethod.MyModule.add 1 2"
    let ch, errors = fsi.EvalInteractionNonThrowing(code, CancellationToken.None)
    errors
    |> Array.iter (fun e -> printfn "error: %A" e)
    match ch with
    | Choice1Of2 v ->
        let v =
            match v with
            | Some v -> sprintf "%A" v.ReflectionValue
            | None -> "(none)"
        printfn "value: %A" v
    | Choice2Of2 e -> printfn "exception: %A" e
    0

Metadata

Metadata

Assignees

Labels

Area-FSIBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.Regression

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions