PyBuffer.GetPointer throws System.ExecutionEngineException when called with an N-dimensional array obtained with PyBUF.ND flag.
dynamic np = Py.Import("numpy");
// create 3D NumPy array
int[] shape = [10, 10, 10];
PyObject ndArray = np.zeros(shape);
PyBuffer buf = ndArray.GetBuffer(PyBUF.ND);
// this throws System.ExecutionEngineException
nint ptr = buf.GetPointer([0, 0, 0]);
I suspect that this may be caused by a mismatch of a type. The following code seems to pass a CLR array to native function pointer.
// src/runtime/Runtime.Delegates.cs
PyBuffer_GetPointer = (delegate* unmanaged[Cdecl]<ref Py_buffer, nint[], IntPtr>)GetFunctionByName(nameof(PyBuffer_GetPointer), GetUnmanagedDll(_PythonDll));
The second argument should be nint* obtained by fixed statement, isn't it?
My environment:
- OS: Windows 11
- Python: 3.14
- Python.NET: 3.1.0
- .NET 10
- Visual Studio 2026
PyBuffer.GetPointerthrowsSystem.ExecutionEngineExceptionwhen called with an N-dimensional array obtained withPyBUF.NDflag.I suspect that this may be caused by a mismatch of a type. The following code seems to pass a CLR array to native function pointer.
The second argument should be
nint*obtained byfixedstatement, isn't it?My environment: