Repository navigation
Exception raised during pretty printing #20860
Copy link
Copy link
Open
Labels
Milestone
Description
Please provide a succinct description of the issue.
Repro steps
open System
open System.Reflection
type InvocableAdapter =
static member ToFunc (f: Func<'Input[], 'Output>) =
printfn "[Match] Single Func"
Func<obj, 'Input[], 'Output>(fun _ args -> f.Invoke(args))
static member ToFunc (f: Func<'Sender, 'Input[], 'Output>) =
printfn "[Match] Double Func"
f
type FSharpFunc<'Input, 'Output> with
static member ToFunc (f: FSharpFunc<'Input[], 'Output >) =
printfn "[Match] FSharpFunc"
Func<obj, 'Input[], 'Output>(fun _ args -> f args)
type InvocableHelper =
static member inline toInvocable (x: ^T) =
printfn "12321"
((^T or InvocableAdapter) : (static member ToFunc : ^T -> _) x)
let f1 = fun (args: obj[]) -> box (String.concat ", " (args |> Seq.map string))
let f2 = fun _ (args: obj[]) -> box args.Length
let fc1 = Func<obj[], obj>(f1)
let fc2 = Func<obj, obj[], obj>(f2)
let inv2 = InvocableHelper.toInvocable fc2
inv2.Invoke(null, [| 1; 2; 3 |]) |> printfn "fc2: %A"
let inv1 = InvocableHelper.toInvocable fc1
inv1.Invoke(null, [| "A"; "B" |]) |> printfn "fc1: %A"
let invF1 = InvocableHelper.toInvocable f1
invF1.Invoke(null, [| "A"; "B" |]) |> printfn "f1: %A"
Expected behavior
No excpetions.
Actual behavior
>
12321
[Match] FSharpFunc
Exception raised during pretty printing.
Please report this so it can be fixed.
Trace: System.InvalidCastException: Unable to cast object of type 'System.Func`3[System.Object,System.Object[][],System.Object]' to type 'System.Func`3[System.Object,System.Object[],System.Object]'.
at FSharp.Compiler.Interactive.Shell.Utilities.AnyToLayoutSpecialization`1.FSharp.Compiler.Interactive.Shell.Utilities.IAnyToLayoutCall.FsiAnyToLayout(FormatOptions options, Object o, Type ty) in D:\a\_work\1\s\src\fsharp\src\Compiler\Interactive\fsi.fs:line 101
at FSharp.Compiler.Interactive.Shell.FsiValuePrinter.PrintValue(FsiValuePrinterMode printMode, FormatOptions opts, Object x, Type ty) in D:\a\_work\1\s\src\fsharp\src\Compiler\Interactive\fsi.fs:line 727
val invF1: Func<obj,obj array,objnull> =
>
Known workarounds
No.
Related information
- Operating system: Win server 2019
- .NET Runtime kind (.NET Core, .NET Framework, Mono): F# Interactive version 15.2.101.0 for F# 11.0
- Editing Tools (e.g. Visual Studio Version, Visual Studio): Visual Studio 2026 Insiders.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
Activity
ingted commentedon Oct 24, 2026
PS. The code works even the assignment of invF1. If you run and stop at
let invF1 = xxxx. After the exception shows, the last expression still works.leads
ingted commentedon Oct 24, 2026
PS. The same code doesn't work in older fsi, e.g. version F# Interactive version 15.2.203.0 for F# 10.0