Title: System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application · Issue #2335 · pythonnet/pythonnet · GitHub
Open Graph Title: System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application · Issue #2335 · pythonnet/pythonnet
X Title: System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application · Issue #2335 · pythonnet/pythonnet
Description: Environment Pythonnet version:3.0.3 Python version:381 Operating System:win11 .NET Runtime:.NET8 Details In my .NET 8 console environment, I executed a simple operation to call a Python method that returns a string. However, I encountere...
Open Graph Description: Environment Pythonnet version:3.0.3 Python version:381 Operating System:win11 .NET Runtime:.NET8 Details In my .NET 8 console environment, I executed a simple operation to call a Python method that...
X Description: Environment Pythonnet version:3.0.3 Python version:381 Operating System:win11 .NET Runtime:.NET8 Details In my .NET 8 console environment, I executed a simple operation to call a Python method that...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2335
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application","articleBody":"### Environment\r\n\r\n- Pythonnet version:3.0.3\r\n- Python version:381\r\n- Operating System:win11\r\n- .NET Runtime:.NET8\r\n\r\n### Details\r\n\r\n- In my .NET 8 console environment, I executed a simple operation to call a Python method that returns a string. However, I encountered an error when executing PythonEngine.Shutdown().\r\n\r\n _TODO_\r\n\r\n- python\u0026code:\r\nimport json\r\ndef return_json_string():\r\n data = {\"message\": \"这是从Python返回的字符串\"}\r\n return \"{\\\"name\\\":\\\"Michael\\\"}\" # 这将会是一个字符串\r\n- .net\u0026code\r\n public static void GetStr()\r\n {\r\n Runtime.PythonDLL = @\"D:\\Program Files\\Python312\\python312.dll\"; // 根据需要更改Python版本和路径\r\n PythonEngine.Initialize(); // 初始化Python引擎\r\n\r\n using (Py.GIL()) // 确保我们在Python全局解释锁(GIL)的上下文中\r\n {\r\n dynamic pyModule = Py.Import(\"ReturnJson\"); // 导入Python方法所在文件名\r\n string result = pyModule.return_json_string(); // 调用函数并获取返回值\r\n\r\n Console.WriteLine(result);\r\n }\r\n\r\n PythonEngine.Shutdown(); // 关闭Python引擎\r\n }\r\n\r\n\r\n```error\r\n System.NotSupportedException: BinaryFormatter 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```\r\n\r\n\r\n","author":{"url":"https://github.com/LiuxinABC","@type":"Person","name":"LiuxinABC"},"datePublished":"2024-03-06T08:05:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2335/pythonnet/issues/2335"}
| 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:96f8d734-aad6-91e3-45ab-59bac7fcac42 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EDA8:184028:315F739:3203792:69702DAF |
| html-safe-nonce | 9aecf3c2908ff11ca31ad5ad690cebeb018160e6fcf2bb57e962938173bde685 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFREE4OjE4NDAyODozMTVGNzM5OjMyMDM3OTI6Njk3MDJEQUYiLCJ2aXNpdG9yX2lkIjoiMTM0MTY1Mjg3NDg1MjA1MjM5OSIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 4d7ae50a758ff7d070a509e2afc62bbae438765eb4aa4876e73b8a0f39c944d6 |
| hovercard-subject-tag | issue:2170882138 |
| 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/2335/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b6a9a2d20020646b4979779ecbbef3ce18426ced4841edfbaf11d14f7868981b/pythonnet/pythonnet/issues/2335 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b6a9a2d20020646b4979779ecbbef3ce18426ced4841edfbaf11d14f7868981b/pythonnet/pythonnet/issues/2335 |
| og:image:alt | Environment Pythonnet version:3.0.3 Python version:381 Operating System:win11 .NET Runtime:.NET8 Details In my .NET 8 console environment, I executed a simple operation to call a Python method that... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LiuxinABC |
| 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