Skip to content

PInvokeStackImbalance #485

Closed
Closed

Description

@DeclanHoare

Environment

  • Pythonnet version: pythonnet_py35_dotnet v2.3.0 (from NuGet)
  • Python version: Python 3.5.3
  • Operating System: Windows 7 x86_64

Details

  • When I try to intialise the interpreter, I get this message:
Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'Python.Runtime!Python.Runtime.Runtime::Py_SetPythonHome' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.'

The code I'm using is

PythonEngine.PythonHome = pypath;
PythonEngine.ProgramName = "PythonAPI";
PythonEngine.Initialize();
pylock = PythonEngine.AcquireLock();
AppDomain.CurrentDomain.ProcessExit += (o, a) => { PythonEngine.ReleaseLock(pylock); };
PythonEngine.Exec(Properties.Resources.PythonAPI);

and the exception occurs on the first line. pypath points to a directory containing the entire contents of the "Windows x86 embeddable zip file" of Python 3.5.3 on python.org.

Activity

  1. den-run-ai commented on Jun 10, 2017

    @den-run-ai
    Contributor
  2. DeclanHoare commented on Jun 11, 2017

    @DeclanHoare
    Author

    Having installed that I can use the clr module from within Python to interact with C# types perfectly, but I can't see how to embed that in my .NET application.

  3. den-run-ai commented on Jun 11, 2017

    @den-run-ai
    Contributor
  4. DeclanHoare commented on Jun 11, 2017

    @DeclanHoare
    Author

    With this method, I get a different exception.

    System.BadImageFormatException: 'Could not load file or assembly 'Python.Runtime, Version=2.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.'
    
  5. den-run-ai commented on Jun 11, 2017

    @den-run-ai
    Contributor
  6. DeclanHoare commented on Jun 11, 2017

    @DeclanHoare
    Author

    But... it doesn't have any instructions on what to do about it.

  7. DeclanHoare commented on Jun 11, 2017

    @DeclanHoare
    Author

    Oh, I'm blind. Sorry.

  8. DeclanHoare commented on Jun 11, 2017

    @DeclanHoare
    Author

    Okay, the library is working perfectly for me now. Thanks for your help. I'm not sure whether to close the issue or not, because of the issue with the NuGet package.

  9. den-run-ai commented on Jun 14, 2017

    @den-run-ai
    Contributor

    This is similar issue as this one:

    #448

    We can close this issue once next release is available.

  10. added this to the 2.4.0 milestone on Jun 14, 2017
  11. filmor commented on Nov 15, 2018

    @filmor
    Member

    As this is apparently fixed on master, I'll close the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions