Title: BinaryFormatter serialization and deserialization warning which throws an error in .net8 · Issue #2282 · pythonnet/pythonnet · GitHub
Open Graph Title: BinaryFormatter serialization and deserialization warning which throws an error in .net8 · Issue #2282 · pythonnet/pythonnet
X Title: BinaryFormatter serialization and deserialization warning which throws an error in .net8 · Issue #2282 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.0.3 Python version: 3.9 Operating System: Windows 11 .NET Runtime: .net8 (release version 16/11/23) Details When shutting down the the PythonEngine via a Dispose method on the impermentation class, the er...
Open Graph Description: Environment Pythonnet version: 3.0.3 Python version: 3.9 Operating System: Windows 11 .NET Runtime: .net8 (release version 16/11/23) Details When shutting down the the PythonEngine via a Dispose me...
X Description: Environment Pythonnet version: 3.0.3 Python version: 3.9 Operating System: Windows 11 .NET Runtime: .net8 (release version 16/11/23) Details When shutting down the the PythonEngine via a Dispose me...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2282
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BinaryFormatter serialization and deserialization warning which throws an error in .net8","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.0.3\r\n- Python version: 3.9\r\n- Operating System: Windows 11\r\n- .NET Runtime: .net8 (release version 16/11/23)\r\n\r\n### Details\r\n\r\n- When shutting down the the PythonEngine via a Dispose method on the impermentation class, the error occurs at the PythonEngine.Shutdown(); method and throws the error System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application (see trace below). The same code worked in .net7 without any issues, the error message leads to this description\r\n- \r\n- https://learn.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide\r\n- \r\n- Proir to the Shutdown error the pythonnet works correctly and calls python functions and returns the expected results\r\n- \r\n- The resolution is to add \u003cEnableUnsafeBinaryFormatterSerialization\u003etrue\u003c/EnableUnsafeBinaryFormatterSerialization\u003e to the .csproj file\r\n- \u003cPropertyGroup\u003e\r\n \u003cTargetFramework\u003enet8.0\u003c/TargetFramework\u003e\r\n \u003cEnableUnsafeBinaryFormatterSerialization\u003etrue\u003c/EnableUnsafeBinaryFormatterSerialization\u003e\r\n \u003c/PropertyGroup\u003e\r\n\r\n\r\n\r\n _TODO_\r\n\r\n\r\n- _logger.Log is to to trace the point of failure \r\n- _logger.Log(LogLevel.Error, \"Shutting down Python engine\"); runs \r\n- it crashes at the PythonEngine.Shutdown(); method \r\n- _logger.Log(LogLevel.Error, \"Python engine shut down\"); does not run\r\n\r\n\r\n private void Dispose(bool disposing)\r\n {\r\n _logger.Log(LogLevel.Error, \"Dispose\");\r\n if (_disposed) return;\r\n if (disposing)\r\n {\r\n _logger.Log(LogLevel.Error, \"Shutting down Python engine\");\r\n PythonEngine.Shutdown();\r\n _logger.Log(LogLevel.Error, \"Python engine shut down\");\r\n }\r\n _disposed = true;\r\n }\r\n\r\n```python\r\n print('TODO')\r\n```\r\n\r\n- System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatt...\r\n\r\nSystem.NotSupportedException\r\nBinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.\r\n at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)\r\n at Python.Runtime.RuntimeData.Stash()\r\n at Python.Runtime.Runtime.Shutdown()\r\n at Python.Runtime.PythonEngine.Shutdown()\r\n at EcgAi.Training.Infrastructure.Python.PythonEnvironment.Dispose(Boolean disposing) in C:\\Data\\Rider\\EcgAi.Training\\Src\\EcgAi.Training.Infrastructure.Python\\PythonEnvironment.cs:line 113\r\n at EcgAi.Training.Infrastructure.Python.PythonEnvironment.Dispose() in xxxxxxxxxxxxxxxxxxxxxxxxx\r\n\r\n```python\r\n print('TODO')\r\n```\r\n","author":{"url":"https://github.com/RobertClapham","@type":"Person","name":"RobertClapham"},"datePublished":"2023-11-16T12:01:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/2282/pythonnet/issues/2282"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:afee7e68-b813-8900-c26f-83aeead846ab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 986C:26FE0E:30E9DD4:31901C8:69702DC7 |
| html-safe-nonce | 6c76916e42f8cf4a14a8900b67c75a5a1bf891e40558b146ba1c405ed3d5616f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODZDOjI2RkUwRTozMEU5REQ0OjMxOTAxQzg6Njk3MDJEQzciLCJ2aXNpdG9yX2lkIjoiMzcyMzE3NDA1ODIyNDc5MDk4MyIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 69a0390ebdee332936213f6c542a70c9cb0f9dc7f49d65bd1a07a43d1650ee0a |
| hovercard-subject-tag | issue:1996704381 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/2282/issue_layout |
| twitter:image | https://opengraph.githubassets.com/82fb8315c6059a65dcdc20e6ed38ec2d9e78aa182e45f8bfc3698c37fe8b6e55/pythonnet/pythonnet/issues/2282 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/82fb8315c6059a65dcdc20e6ed38ec2d9e78aa182e45f8bfc3698c37fe8b6e55/pythonnet/pythonnet/issues/2282 |
| og:image:alt | Environment Pythonnet version: 3.0.3 Python version: 3.9 Operating System: Windows 11 .NET Runtime: .net8 (release version 16/11/23) Details When shutting down the the PythonEngine via a Dispose me... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RobertClapham |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01fa379f5de85ef8e791d09724e69709ce9eb9595278316e0a921312dc88e0bc |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dda91974c069382b0dfa47b2da7e28bd061c8331 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width