GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application · Issue #2335 · pythonnet/pythonnet

System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application #2335

New issue
Copy link
New issue
Copy link
Closed
Closed
System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application#2335
Copy link

Description

@LiuxinABC
LiuxinABC
opened on Mar 6, 2024
Issue body actions

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 encountered an error when executing PythonEngine.Shutdown().

    TODO

  • python&code:
    import json
    def return_json_string():
    data = {"message": "这是从Python返回的字符串"}
    return "{"name":"Michael"}" # 这将会是一个字符串

  • .net&code
    public static void GetStr()
    {
    Runtime.PythonDLL = @"D:\Program Files\Python312\python312.dll"; // 根据需要更改Python版本和路径
    PythonEngine.Initialize(); // 初始化Python引擎

    using (Py.GIL()) // 确保我们在Python全局解释锁(GIL)的上下文中
    {
    dynamic pyModule = Py.Import("ReturnJson"); // 导入Python方法所在文件名
    string result = pyModule.return_json_string(); // 调用函数并获取返回值

    Console.WriteLine(result);
    

    }

    PythonEngine.Shutdown(); // 关闭Python引擎
    }

    System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at Python.Runtime.RuntimeData.Stash()
   at Python.Runtime.Runtime.Shutdown()
   at Python.Runtime.PythonEngine.Shutdown()

Activity

  1. filmor commented on Sep 19, 2024

    @filmor
    filmor
    on Sep 19, 2024
    Member
    More actions

    This should be fixed now.

  2. filmor
    closed this as completedon Sep 19, 2024
  3. nwoolls commented on Oct 21, 2024

    @nwoolls
    nwoolls
    on Oct 21, 2024
    More actions

    @filmor is this fix available on NuGet? I'm still seeing this issue with the latest 3.1 preview version on NuGet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.