Thanks to visit codestin.com
Credit goes to github.com

Skip to content

.net8.0 System.AggregateException:BinaryFormatter serialization and deserialization are disabled within this application. #2532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
732857315 opened this issue Dec 18, 2024 · 1 comment

Comments

@732857315
Copy link

Environment

  • Pythonnet version: 3.1.0-preview2024-09-06
  • Python version: 3.8.10
  • Operating System: Win10
  • .NET Runtime: dotnet8.0 core

Details

  • Describe what you were trying to get done.

    I want use python in dotnet ,but this dotnet evenment can not exit ,so i use func shutdown,but the C# evenment have an Exception:System.AggregateException: One or more errors occurred. (BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.)
    ---> 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() in D:\work\vsprj\HDC_Instrament2024new\HDC_InstramentForPythonTkinter\pythonnet-master\src\runtime\StateSerialization\RuntimeData.cs:line 96
    at Python.Runtime.Runtime.Shutdown() in D:\work\vsprj\HDC_Instrament2024new\HDC_InstramentForPythonTkinter\pythonnet-master\src\runtime\Runtime.cs:line 272
    at Python.Runtime.PythonEngine.Shutdown() in D:\work\vsprj\HDC_Instrament2024new\HDC_InstramentForPythonTkinter\pythonnet-master\src\runtime\PythonEngine.cs:line 392

  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.

//功能测试
bool taskrun = true;
Task.Run(async () =>
{
    // install in local directory
    Installer.InstallPath = Path.GetFullPath(".");
    // see what the installer is doing
    Installer.LogMessage += Console.WriteLine;
    bool loadend = false;

    await Installer.SetupPython();
    if (!Installer.IsPipInstalled())
    {
        await Installer.TryInstallPip();
    }
    if (!Installer.IsModuleInstalled("numpy"))
    {
        await Installer.PipInstallModule("numpy");
    }
    loadend = true;

    while (!loadend) ;
    PythonEngine.Initialize();


    try
    {
        // call Python's sys.version to prove we are executing the right version
        dynamic sys = Py.Import("sys");
        Console.WriteLine("### Python version:\n\t" + sys.version);

        // call os.getcwd() to prove we are executing the locally installed embedded python distribution
        dynamic os = Py.Import("os");
        Console.WriteLine("### Current working directory:\n\t" + os.getcwd());
        Console.WriteLine("### PythonPath:\n\t" + PythonEngine.PythonPath);

        dynamic np = Py.Import("numpy"); // 导入numpy模块
        dynamic sin = np.sin;
        int[] data = new int[] { 0, 1, 2, 3 };
        var a = np.array(data);
        var result = sin(a);
        Console.WriteLine("Numpy sin:");
        Console.WriteLine(result);


        dynamic tkinter = Py.Import("tkinter"); // 导入tkinter模块
        var top = tkinter.Tk();
        // 进入消息循环
        top.mainloop();

    }
    catch (PythonException e)
    {
        Console.WriteLine($"{e}");
    }
   
    PythonEngine.Shutdown();
}).ContinueWith((e) => {
    Console.WriteLine($"{e.Exception}");
    taskrun = false;
});
while (taskrun) ;
  • If there was a crash, please include the traceback here.
     One or more errors occurred. (BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.)
 ---> 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() in D:\work\vsprj\HDC_Instrament2024new\HDC_InstramentForPythonTkinter\pythonnet-master\src\runtime\StateSerialization\RuntimeData.cs:line 96
   at Python.Runtime.Runtime.Shutdown() in D:\work\vsprj\HDC_Instrament2024new\HDC_InstramentForPythonTkinter\pythonnet-master\src\runtime\Runtime.cs:line 272
   at Python.Runtime.PythonEngine.Shutdown() in D:\work\vsprj\HDC_Instrament2024new\HDC_InstramentForPythonTkinter\pythonnet-master\src\runtime\PythonEngine.cs:line 392
@filmor
Copy link
Member

filmor commented Dec 18, 2024

This is a duplicate of #2469.

@filmor filmor closed this as completed Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants