question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No method matches given arguments with optional parameters

See original GitHub issue

Environment

  • 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:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lostmsucommented, Apr 4, 2022

@jaqueamo yes, specifically Bind method.

0reactions
jaqueamocommented, Apr 4, 2022

It works fine if you use System.Int32.

Is the MethodBinder class the entry point for the overload resolution ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pythonnet TypeError: No method matches given arguments ...
I have loaded the dll file and when I call a function I receive - TypeError: No method matches given arguments for Connect:...
Read more >
Mailman 3 "TypeError: No method matches given arguments ...
This seems to come up semi-regularly from a web search, but I have been unable to converge on a solution.
Read more >
Named And Optional Parameters In C#
The parameters name must match with the method definition parameter names. The syntax of parameter names is (parametername: value).
Read more >
Rhino Inside Python: "No method matches..." - McNeel Forum
As far as I can tell I'm supplying parameters of the types I need to according to the API, but for some reason...
Read more >
Dynamo 2.7 Migrating MaRS to CPython3
TypeError : No method matches given arguments for method. This usually seems to be due to a mismatch between ints and floats, something...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found