You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Operating System: Windows 11 (Same happens when running on WSL - Ubuntu)
.NET Runtime: .NET 7
Details
Calling Python.Runtime.PythonEngine.Shutdown(); results in the error:
System.NotSupportedException: 'BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.'
We need to call Shutdown (in my opinion) just as well to ensure that destructors run in a sensible order. What we definitely don't need to do is the stashing part. It only needs to run if we want to reload domains, which is not supported on .NET Core anyway. I'm currently working on this (and related slowness during shutdowns) here:
I recently tried pythonnet in C# Console Application in Visual Studio 2022.
Environment
Pythonnet version: 3.0.3
Python version: 3.12.3
Operating System: Windows 11 23H2
.NET Runtime: .NET 8
For now, Shutdown is needed, because without it, one of the threads does not allow the process to end completely.
Then I tried to call Shutdown but got this exception in the PR.
In this case, need to add <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization> to the project file. Even with this flag, the process does not terminate without Shutdown.
And after this flag and call Shutdown the process ends correctly.
Activity
[-]PythonEngine.Shutdown() Error[/-][+]PythonEngine.Shutdown() Crash[/+]filmor commentedon Feb 23, 2023
Workaround here: #2008 (comment)
lostmsu commentedon May 3, 2023
@filmor do we even need
Shutdownon .NET Core?filmor commentedon Sep 23, 2023
We need to call
Shutdown(in my opinion) just as well to ensure that destructors run in a sensible order. What we definitely don't need to do is the stashing part. It only needs to run if we want to reload domains, which is not supported on .NET Core anyway. I'm currently working on this (and related slowness during shutdowns) here:#2245
JKingas commentedon Jun 4, 2024
I recently tried pythonnet in C# Console Application in Visual Studio 2022.
Environment
For now,
Shutdownis needed, because without it, one of the threads does not allow the process to end completely.Then I tried to call
Shutdownbut got this exception in the PR.In this case, need to add
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>to the project file. Even with this flag, the process does not terminate withoutShutdown.And after this flag and call
Shutdownthe process ends correctly.filmor commentedon Sep 19, 2024
This should be fixed now.