fsharp
fsharp copied to clipboard
Problem consuming C# API with default value for parameter
Please provide a succinct description of the issue.
Repro steps
Provide the steps required to reproduce the problem:
- Load a C# library that defines a method that takes a default value
- From F# call the method without specifying the value3.
Expected behavior
Expects that the following snippet compiles:
#r "nuget: FluentAssertions.Json, 6.1.0"
open FluentAssertions.Json
open Newtonsoft.Json.Linq
let assertJsonEqual expected actual =
let expectedToken = JToken.Parse expected
let actualToken = JToken.Parse actual
actualToken.Should().BeEquivalentTo(expectedToken) |> ignore
Actual behavior
The member or object constructor 'BeEquivalentTo' does not take 1 argument(s). An overload was found taking 3 arguments.F# Compiler505
Known workarounds
A workaround is to specify the default values explicitly:
#r "nuget: FluentAssertions.Json, 6.1.0"
open FluentAssertions.Json
open Newtonsoft.Json.Linq
let assertJsonEqual expected actual =
let expectedToken = JToken.Parse expected
let actualToken = JToken.Parse actual
actualToken.Should().BeEquivalentTo(expected = expectedToken, because = "") |> ignore
Related information
Provide any related information (optional):
- Operating systems: Windows 11, macOS Monterey 12.4
- .NET Runtime kinds: .NET Core 6.0.300 , 3.1.421
- Editing Tools: Rider 2022.1.2, Visual Studio Community 2022 for Mac Preview (17.3 build 198), Visual Studio Code and Ionide
Looks like this involves interop with methods that have both omitted optional arguments and ParamArray arguments:
BeEquivalentTo(class [Newtonsoft.Json]Newtonsoft.Json.Linq.JToken expected,
[opt] string because,
object[] becauseArgs) cil managed