Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Parameter resolution for integer types doesn't work in some cases #1523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
slide opened this issue Aug 21, 2021 · 2 comments · Fixed by #1531
Closed

Parameter resolution for integer types doesn't work in some cases #1523

slide opened this issue Aug 21, 2021 · 2 comments · Fixed by #1531

Comments

@slide
Copy link
Contributor

slide commented Aug 21, 2021

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.

@slide slide mentioned this issue Aug 21, 2021
3 tasks
@rayrapetyan
Copy link

Will that handle properly cases where both long\ulong overloads are available, e.g.:

  public class MethodResolutionInt
  {
      public IEnumerable<byte> MethodA(ulong address, int size)
      {
          return new byte[10];
      }

      public int MethodA(long address, int size)
      {
          return 0;
      }
  }

lostmsu added a commit to losttech/pythonnet that referenced this issue Aug 25, 2021
@lostmsu
Copy link
Member

lostmsu commented Aug 25, 2021

@rayrapetyan for this I strongly recommend to use manual overload resolution. E.g. inst.MethodA.Overloads[UInt64, Int32](...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants