Skip to content

Interop with C# method with optional argument and params #1120

@lucasteles

Description

@lucasteles

This case happened to me when I was using FluentAssertions, when I try to call a C# method that receives the first argument with a default value and a second params argument I can't omit both parameters.

E.g:

    public class Class1
    {
        public static string Foo(string something = "", params object[] args) => 
            string.Format(something, args);
    }

If I try to use this method in F# I expected to be able to call it in this way:

 let result1 = Class1.Foo()

But this gives me an error :

Error FS0501: 
The member or object constructor 'Foo' takes 2 argument(s) but is here given 0. 
The required signature is 'Class1.Foo(?something: string, [<System.ParamArray>] args: obj[]) : string'.

So, to make it work I need to pass the first argument explicitly which I would expect to be optional :

 let result1 = Class1.Foo("")

Pros and Cons

I don't know if this is bt design, but is very confusing and made the interop harder and noisy in some cases.

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions