Closed
Description
Environment
- Pythonnet version: 2.3.0 and 2.4.0
- Python version: 3.6.5
- Operating System: W10
Details
- I'm having issues disambiguating an overloaded C# method that has multiple parameters. I've found TypeError when calling a method with an enum argument #935 which is a very similar issue but can't get it to work. I'm following the same steps but I still get the same error.
The C# side
public enum MyEnum: byte
{
Success= (byte)'S',
Error = (byte)'E'
}
public class MyClass
{
public Dictionary<Enum, BlockingCollection<ISomeInterface>> MyDictionary { get; }
public MyClass()
{
MyDictionary = new Dictionary<Enum, BlockingCollection<ISomeInterface>>();
}
}
On the python side, I began with this code
from System.Collections.Concurrent import BlockingCollection
from MyModule import MyClass, ISomeInterface, MyEnum
obj = MyClass()
collection = BlockingCollection[ISomeInterface]()
obj.MyDictionary.Add(MyEnum.Success, collection)
This fails with TypeError: No method matches given arguments for Add
. I've tried what seemed to solve it for #935 but get the same results
from System.Collections.Concurrent import BlockingCollection
from System import Enum
from MyModule import MyClass, ISomeInterface, MyEnum
obj = MyClass()
collection = BlockingCollection[ISomeInterface]()
obj.MyDictionary.Add[Enum, BlockingCollection[ISomeInterface]](MyEnum.Success, collection)
This fails with TypeError: No match found for given type params
- The output of
print(obj.MyDictionary.Add.__overloads__)
is
Void Add(System.Enum, System.Collections.Concurrent.BlockingCollection`1[MyModule.ISomeInterface])
UPDATE
Running this code alone actually works, add
shows as a bound method in the debugger:
add = obj.MyDictionary.Add.Overloads[Enum, BlockingCollection[ISomeInterface]]
However, attempting to call the function always fails. I've attempted passing System.byte and 0, instead of the enum, but none of them work.
add(MyEnum.Success, collection)
obj.MyDictionary.Add[Enum, BlockingCollection[ISomeInterface]](MyEnum.Success, collection)
obj.MyDictionary.Add.Overloads[Enum, BlockingCollection[ISomeInterface]](MyEnum.Success, collection)
Metadata
Metadata
Assignees
Labels
No labels