No method matches given arguments with optional parameters
See original GitHub issueEnvironment
- Pythonnet version: 3.0.0-preview2022-03-03
- Python version: 3.8.3 / 3.10.4
- Operating System: Windows 10
- .NET Runtime: dotnet framework 4.8
Details
- Describe what you were trying to get done.
I have a C# method with two overloads. The method has an optional parameter. The only difference is the type of the value parameter (double and int).
public void Foo(string foo, string foobar, int value, int? fooOptional = null)
{ }
public void Foo(string foo, string foobar, double value, int? fooOptional = null)
{ }
If I call the method from python:
p.Foo("foo", "bar", 1)
I get the following error message:
Exception has occurred: TypeError (note: full exception trace is shown but execution is paused at: <module>) No method matches given arguments for Exec.Foo: (<class ‘str’>, <class ‘str’>, <class ‘int’>)
I investigated the problem a bit more: If I remove the optional parameters from the C# method it’s working. If I change the type of the value parameter from int to string it’s working.
public void Foo(string foo, string foobar, string value, int? fooOptional = null)
{ }
If I call from python with a float (and not int) it’s working.
p.Foo("foo", "bar", 1.0)
So my conclusion is it must have something to do with the optional parameters and the type (double, int) before the optional parameter.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@jaqueamo yes, specifically
Bind
method.It works fine if you use System.Int32.
Is the MethodBinder class the entry point for the overload resolution ?