pythonnet: Using String.Format crashes inside pythonnet

Environment

  • Pythonnet version: 3.x
  • Python version: 3.8.10
  • Operating System: Windows 11 64bit
  • .NET Runtime: net6.0

Details

How to reproduce(with project Console.vsproj): @filmor

PythonEngine.Initialize();
PythonEngine.Exec("from System import String\nString.Format('{0},{1}', 1, 2)"); // crashes here
int i = Runtime.Py_Main(cmd.Length, cmd);
PythonEngine.Shutdown();

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

System.AccessViolationException: ‘Attempted to read or write protected memory. This is often an indication that other memory is corrupt.’ [External Code]

Python.Runtime.dll!Python.Runtime.Runtime.PyErr_Occurred() Line 1853 C# Python.Runtime.dll!Python.Runtime.Exceptions.ErrorOccurred() Line 315 C# Python.Runtime.dll!Python.Runtime.Runtime.AssertNoErorSet() Line 1130 C# Python.Runtime.dll!Python.Runtime.Runtime.PyObject_Str(Python.Runtime.BorrowedReference pointer) Line 1122 C# Python.Runtime.dll!Python.Runtime.PyObject.ToString() Line 1054 C# [External Code] Python.Runtime.dll!Python.Runtime.MethodBinder.Invoke(Python.Runtime.BorrowedReference inst, Python.Runtime.BorrowedReference args, Python.Runtime.BorrowedReference kw, System.Reflection.MethodBase info, System.Reflection.MethodInfo[] methodinfo) Line 919 C# Python.Runtime.dll!Python.Runtime.MethodObject.Invoke(Python.Runtime.BorrowedReference target, Python.Runtime.BorrowedReference args, Python.Runtime.BorrowedReference kw, System.Reflection.MethodBase info) Line 68 C# Python.Runtime.dll!Python.Runtime.MethodBinding.tp_call(Python.Runtime.BorrowedReference ob, Python.Runtime.BorrowedReference args, Python.Runtime.BorrowedReference kw) Line 238 C# [External Code] Python.Runtime.dll!Python.Runtime.Runtime.PyRun_String(string code, Python.Runtime.RunFlagType st, Python.Runtime.BorrowedReference globals, Python.Runtime.BorrowedReference locals) Line 941 C# Python.Runtime.dll!Python.Runtime.PythonEngine.RunString(string code, Python.Runtime.BorrowedReference globals, Python.Runtime.BorrowedReference locals, Python.Runtime.RunFlagType flag) Line 670 C# Python.Runtime.dll!Python.Runtime.PythonEngine.Exec(string code, Python.Runtime.PyDict globals, Python.Runtime.PyObject locals) Line 578 C# nPython.exe!Python.Runtime.PythonConsole.Main(string[] args) Line 36 C#