Repository navigation
Parameter resolution for integer types doesn't work in some cases #1523
Copy link
Copy link
Closed
Description
Environment
- Pythonnet version: master
- Python version: 3.7
- Operating System: Windows 10
- .NET Runtime: .NET 4.8
Details
- Describe what you were trying to get done.
Calling .NET methods from Python
- What commands did you run to trigger this issue?
Given a class like the following, any value you pass for address to the first MethodA will cause the exception underneath, it looks like because when needsResolution is true, the Converter will see the the value as an Int32 in GetTypeByAlias since in 3.7 there is no distinction between int and long anymore.
public class MethodResolutionInt
{
public IEnumerable<byte> MethodA(ulong address, int size)
{
return new byte[10];
}
public int MethodA(string dummy, ulong address, int size)
{
return 0;
}
}mri = MethodResolutionInt()
data = list(mri.MethodA(0x1000, 10))
assert len(data) == 10
assert data[0] == 0
data = list(mri.MethodA(0x100000000, 10))
assert len(data) == 10
assert data[0] == 0- If there was a crash, please include the traceback here.
Python.Runtime.PythonException: Expected UInt64, got Int32
The above exception was the direct cause of the following exception:
Python.Runtime.PythonException: Expected UInt64, got Int32
The above exception was the direct cause of the following exception:
System.ArgumentException: Expected UInt64, got Int32 in method System.Collections.Generic.IEnumerable`1[System.Byte] MethodA(UInt64, Int32) ---> Python.Runtime.PythonException: Expected UInt64, got Int32
--- End of inner exception stack trace ---
The above exception was the direct cause of the following exception:
Python.Runtime.PythonException: Expected UInt64, got Int32
The above exception was the direct cause of the following exception:
System.ArgumentException: Expected UInt64, got Int32 in method System.Collections.Generic.IEnumerable`1[System.Byte] MethodA(UInt64, Int32) ---> Python.Runtime.PythonException: Expected UInt64, got Int32
--- End of inner exception stack trace ---
The above exception was the direct cause of the following exception:
System.AggregateException: One or more errors occurred. ---> System.ArgumentException: Expected UInt64, got Int32 in method System.Collections.Generic.IEnumerable`1[System.Byte] MethodA(UInt64, Int32) ---> Python.Runtime.PythonException: Expected UInt64, got Int32
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.ArgumentException: Expected UInt64, got Int32 in method System.Collections.Generic.IEnumerable`1[System.Byte] MethodA(UInt64, Int32) ---> Python.Runtime.PythonException: Expected UInt64, got Int32
--- End of inner exception stack trace ---<---
I have a PR almost ready with A solution to the issue, but it may not be the correct solution.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
rayrapetyan commentedon Aug 23, 2021
Will that handle properly cases where both long\ulong overloads are available, e.g.:
remove needsResolution hack
lostmsu commentedon Aug 25, 2021
@rayrapetyan for this I strongly recommend to use manual overload resolution. E.g.
inst.MethodA.Overloads[UInt64, Int32](...)remove needsResolution hack