- Notifications
You must be signed in to change notification settings - Fork750
Description
Environment
- Pythonnet version: 2.5.1
- Python version: 3.8.2
- Operating System: Windows 10
Details
In PythonNet 2.5.1, I found correct/appropriate overloaded .Net methods are not invoked from Python while executing .Net code statements
for example please find the below code throws an error while trying to execute System.Data.DataRowCollection.Add(System.Data.DataRow) method.
Reference:https://docs.microsoft.com/en-us/dotnet/api/system.data.datarowcollection.add?view=netframework-4.8
Code:
#PYTHON 3.8.x PYTHONNET 2.5.1importclrclr.AddReference("System")clr.AddReference("System.Data")importSystemimportSystem.Datadt=System.Data.DataTable()col=System.Data.DataColumn()col.ColumnName="Id"col.DataType=System.Type.GetType("System.Int32")dt.Columns.Add(col)dr=dt.NewRow()dr["Id"]=10#Throws error while invoking void System.Data.DataRowCollection.Add(System.Data.DataRow row)try:dt.Rows.Add(dr)exceptExceptionase:print(e)#Working as expected while invoking System.Data.DataRow Add (params object[] values)dr=dt.Rows.Add(20)print(dr[0])
params_overloaded_function_precedence_issue.py.txt
Unable to cast object of type 'System.Data.DataRow' to type 'System.IConvertible'.Couldn't store <System.Data.DataRow> in Id Column. Expected type is Int32.
at System.Data.DataColumn.set_Item(Int32 record, Object value)
at System.Data.DataTable.NewRecordFromArray(Object[] value)
at System.Data.DataRowCollection.Add(Object[] values)
I could fix this issue in local repo by patching Python.Runtime.MethodBinder.GetPrecedence method, I set lower precedence to overloaded methods with Params array parameter
Please have a look and let me know your suggestions
-Parthasarathy K