05-19-2025, 04:27 PM
Catch the exception.
https://github.com/pythonnet/pythonnet/issues/2469
public void Dispose() {
_m?.Dispose();
_gil?.Dispose();
if (_shutdown) {
try { PythonEngine.Shutdown(); } //without this the process does not exit
catch (System.Runtime.Serialization.SerializationException) { } //thrown when using enablePrint
catch (PlatformNotSupportedException) { } //.NET 9+: BinaryFormatter serialization and deserialization have been removed
}
}
https://github.com/pythonnet/pythonnet/issues/2469