03-21-2026, 07:02 PM
Python.NET update for me, at least: the binary format serializer problem has FINALLY been dealt with by the pythonnet people. I used Tools-Nuget-Update for the PythonNet nupkg to 3.10.rc0. Now this code will work, with no shutdown problem.
/*/ nuget PyNet\PythonNet; /*/
using Python.Runtime;
PythonEngine.Initialize();
using (Py.GIL()) {
// NOTE: this doesn't validate input
if (!dialog.showInput(out string firstCsharpNumber, "Enter first number:")) return;
PyObject firstNumber = Convert.ToDouble(firstCsharpNumber).ToPython();
if (!dialog.showInput(out string secondCsharpNumber, "Enter second number:")) return;
PyObject secondNumber = Convert.ToDouble(secondCsharpNumber).ToPython();
dynamic scope = Py.CreateScope();
scope.Exec("def add(a, b): return a + b");
var sum = scope.add(firstNumber, secondNumber);
print.it("Sum: " + (int)sum);
Py.GIL().Dispose();
}
PythonEngine.Shutdown();