@@ -436,6 +436,7 @@ private static void AddVirtualMethod(MethodInfo method, Type baseType, TypeBuild
436
436
il . Emit ( OpCodes . Ldloc_0 ) ;
437
437
438
438
il . Emit ( OpCodes . Ldtoken , method ) ;
439
+ il . Emit ( OpCodes . Ldtoken , method . DeclaringType ) ;
439
440
#pragma warning disable CS0618 // PythonDerivedType is for internal use only
440
441
if ( method . ReturnType == typeof ( void ) )
441
442
{
@@ -698,7 +699,7 @@ public class PythonDerivedType
698
699
/// class) it calls it, otherwise it calls the base method.
699
700
/// </summary>
700
701
public static T ? InvokeMethod < T > ( IPythonDerivedType obj , string methodName , string origMethodName ,
701
- object [ ] args , RuntimeMethodHandle methodHandle )
702
+ object [ ] args , RuntimeMethodHandle methodHandle , RuntimeTypeHandle declaringTypeHandle )
702
703
{
703
704
var self = GetPyObj ( obj ) ;
704
705
@@ -724,7 +725,8 @@ public class PythonDerivedType
724
725
}
725
726
726
727
PyObject py_result = method . Invoke ( pyargs ) ;
727
- PyTuple ? result_tuple = MarshalByRefsBack ( args , methodHandle , py_result , outsOffset : 1 ) ;
728
+ var clrMethod = MethodBase . GetMethodFromHandle ( methodHandle , declaringTypeHandle ) ;
729
+ PyTuple ? result_tuple = MarshalByRefsBack ( args , clrMethod , py_result , outsOffset : 1 ) ;
728
730
return result_tuple is not null
729
731
? result_tuple [ 0 ] . As < T > ( )
730
732
: py_result . As < T > ( ) ;
@@ -754,7 +756,7 @@ public class PythonDerivedType
754
756
}
755
757
756
758
public static void InvokeMethodVoid ( IPythonDerivedType obj , string methodName , string origMethodName ,
757
- object ? [ ] args , RuntimeMethodHandle methodHandle )
759
+ object ? [ ] args , RuntimeMethodHandle methodHandle , RuntimeTypeHandle declaringTypeHandle )
758
760
{
759
761
var self = GetPyObj ( obj ) ;
760
762
if ( null != self . Ref )
@@ -779,7 +781,8 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s
779
781
}
780
782
781
783
PyObject py_result = method . Invoke ( pyargs ) ;
782
- MarshalByRefsBack ( args , methodHandle , py_result , outsOffset : 0 ) ;
784
+ var clrMethod = MethodBase . GetMethodFromHandle ( methodHandle , declaringTypeHandle ) ;
785
+ MarshalByRefsBack ( args , clrMethod , py_result , outsOffset : 0 ) ;
783
786
return ;
784
787
}
785
788
}
@@ -811,12 +814,11 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s
811
814
/// as a tuple of new values for those arguments, and updates corresponding
812
815
/// elements of <paramref name="args"/> array.
813
816
/// </summary>
814
- private static PyTuple ? MarshalByRefsBack ( object ? [ ] args , RuntimeMethodHandle methodHandle , PyObject pyResult , int outsOffset )
817
+ private static PyTuple ? MarshalByRefsBack ( object ? [ ] args , MethodBase ? method , PyObject pyResult , int outsOffset )
815
818
{
816
- if ( methodHandle == default ) return null ;
819
+ if ( method is null ) return null ;
817
820
818
- var originalMethod = MethodBase . GetMethodFromHandle ( methodHandle ) ;
819
- var parameters = originalMethod . GetParameters ( ) ;
821
+ var parameters = method . GetParameters ( ) ;
820
822
PyTuple ? outs = null ;
821
823
int byrefIndex = 0 ;
822
824
for ( int i = 0 ; i < parameters . Length ; ++ i )
0 commit comments