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

Skip to content

Invalid method binding with specified .NET parameters #486

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
Konstantin-Posudevskiy opened this issue Jun 12, 2017 · 1 comment
Closed
Labels
Milestone

Comments

@Konstantin-Posudevskiy
Copy link
Contributor

Environment

  • Pythonnet version: 2.3.0.0
  • Python version: 3.5.3
  • Operating System: Windows 10.

Details

  • Call to .NET method fails with passed arguments (Double.NegativeInfinity, Double.PositiveInfinity, Single.NegativeInfinity, Single.PositiveInfinity).
    There is an example, how you can reproduce this bug.

C# code

namespace Bugs
{
    public class InvalidMethodBinding
    {
        public static void WriteDouble(System.Double value)
        {
            System.Console.WriteLine(value);
        }
    }
}

Python code:

import clr

clr.AddReference('PathToDll')

from System import Double
from Bugs import *

InvalidMethodBinding.WriteDouble(0.01)
InvalidMethodBinding.WriteDouble(Double.NegativeInfinity)
  • Traceback:
Traceback (most recent call last):
0.01
  File "X", line Y, in <module>
    Program.WriteDouble(Double.NegativeInfinity)
TypeError: No method matches given arguments
Konstantin-Posudevskiy added a commit to Konstantin-Posudevskiy/pythonnet that referenced this issue Jun 12, 2017
Fix problem of conversion 'float' and 'double' values in converter.cs.
As there was a range check both for 'float' and 'double' values, which
are less or greater than its 'MinValue' and 'MaxValue' accordingly,
several values like 'float.NegativeInfinity', 'float.PositiveInfinity'
and the same 'double' values cannot be converted from Python to .NET
values.

Add error check after 'PyFloat_AsDouble' call.
Due to Python C API documentation, method 'PyFloat_AsDouble' can return
'-1.0' upon failure. So it requires error check. This rule forces to
check for error and throw exception in case of error.

Add tests, which cover problem of conversion 'float' and 'double'
values.

Resolves: pythonnet#486.
Konstantin-Posudevskiy added a commit to Konstantin-Posudevskiy/pythonnet that referenced this issue Jun 12, 2017
Fix problem of conversion 'float' and 'double' values in converter.cs.
As there was a range check both for 'float' and 'double' values, which
are less or greater than its 'MinValue' and 'MaxValue' accordingly,
several values like 'float.NegativeInfinity', 'float.PositiveInfinity'
and the same 'double' values cannot be converted from Python to .NET
values.

Add error check after 'PyFloat_AsDouble' call.
Due to Python C API documentation, method 'PyFloat_AsDouble' can return
'-1.0' upon failure. So it requires error check. This rule forces to
check for error and throw exception in case of error.

Add tests, which cover problem of conversion 'float' and 'double'
values.

Resolves: pythonnet#486.
@den-run-ai
Copy link
Contributor

related: #100

@den-run-ai den-run-ai added the bug label Jun 14, 2017
@den-run-ai den-run-ai added this to the 2.4.0 milestone Jun 14, 2017
den-run-ai pushed a commit that referenced this issue Jun 14, 2017
* Fix conversion of 'float' and 'double' values

Fix problem of conversion 'float' and 'double' values in converter.cs.
As there was a range check both for 'float' and 'double' values, which
are less or greater than its 'MinValue' and 'MaxValue' accordingly,
several values like 'float.NegativeInfinity', 'float.PositiveInfinity'
and the same 'double' values cannot be converted from Python to .NET
values.

Add error check after 'PyFloat_AsDouble' call.
Due to Python C API documentation, method 'PyFloat_AsDouble' can return
'-1.0' upon failure. So it requires error check. This rule forces to
check for error and throw exception in case of error.

Add tests, which cover problem of conversion 'float' and 'double'
values.

Resolves: #486.

* Fix failing 'test_double_conversion' test

Fix incorrect part of 'test_double_conversion' test in test_conversion.py.
An 'OverflowError' was expected for valid values, which represent Python
'inf' and '-inf'.
The problem was identified with support of conversion for Python 'inf'
and '-inf' to .NET System.Double PositiveInfinity and NegativeInfinity.

See also: #487.
testrunner123 pushed a commit to testrunner123/pythonnet that referenced this issue Sep 22, 2017
* Fix conversion of 'float' and 'double' values

Fix problem of conversion 'float' and 'double' values in converter.cs.
As there was a range check both for 'float' and 'double' values, which
are less or greater than its 'MinValue' and 'MaxValue' accordingly,
several values like 'float.NegativeInfinity', 'float.PositiveInfinity'
and the same 'double' values cannot be converted from Python to .NET
values.

Add error check after 'PyFloat_AsDouble' call.
Due to Python C API documentation, method 'PyFloat_AsDouble' can return
'-1.0' upon failure. So it requires error check. This rule forces to
check for error and throw exception in case of error.

Add tests, which cover problem of conversion 'float' and 'double'
values.

Resolves: pythonnet#486.

* Fix failing 'test_double_conversion' test

Fix incorrect part of 'test_double_conversion' test in test_conversion.py.
An 'OverflowError' was expected for valid values, which represent Python
'inf' and '-inf'.
The problem was identified with support of conversion for Python 'inf'
and '-inf' to .NET System.Double PositiveInfinity and NegativeInfinity.

See also: pythonnet#487.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants