Skip to content

Problem consuming C# API with default value for parameter #13519

Closed

Description

@wallymathieu

Please provide a succinct description of the issue.

Repro steps

Provide the steps required to reproduce the problem:

  1. Load a C# library that defines a method that takes a default value
  2. 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

Activity

  1. changed the title [-]Problem consuming API with default value[/-] [+]Problem consuming C# API with default value for parameter[/+] on Jul 16, 2022
  2. added this to the Backlog milestone on Sep 9, 2022
  3. added
    Area-Compiler-ImportAndInterop
    on Sep 9, 2022
  4. dsyme commented on Sep 21, 2022

    @dsyme
    Contributor

    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
    
  5. self-assigned this
    on Sep 21, 2022
  6. added
    Impact-Medium
    on Sep 21, 2022
  7. github-actions commented on Mar 20, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    I tested this issue against the current F# 10 SDK (.NET 9.0) and it now compiles successfully without needing to specify the optional parameters explicitly:

    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  // ✅ now compiles

    This was fixed as part of F# support for calling C# methods with optional/default parameters by omitting optional arguments (related to C# interop improvements in F# 8+). The workaround of specifying expected = expectedToken, because = "" is no longer needed.

    This issue may be eligible for closure. Could a maintainer verify and close if confirmed?

    Generated by Repo Assist · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@9135cdfde26838a01779aa966628308404ec1f02
    
  8. auduchinok commented on Mar 23, 2026

    @auduchinok
    Member

    Let's add a test before closing?

  9. added 3 commits that reference this issue on Mar 24, 2026
  10. added 3 commits that reference this issue on Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AI-thinks-issue-fixedArea-Compiler-ImportAndInteropBugImpact-Medium

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions