ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.28k stars 121 forks source link

Error PInvokeStackImbalance in runtime #417

Closed wasabii closed 1 year ago

wasabii commented 1 year ago

Discussed in https://github.com/orgs/ikvmnet/discussions/415

Originally posted by **mknezevic** September 6, 2023 Hi, I have a .NET project in which uses a dll created from a jar file using IkvmReference. The project builds successfully and the corresponding dll is created. However, during runtime I'm getting the error: `Managed Debugging Assistant 'PInvokeStackImbalance' Message=Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'IKVM.Runtime!IKVM.Runtime.JNI.JNIVM+LibJvm+Set_JNI_GetDefaultJavaVMInitArgsDelegate::Invoke' 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.'` Any thoughts? I use: Visual Studio 2022 .NET Framework 4.8.1 IKVM 8.6.2 The jar that I use is grobid-core version 0.7.1 https://github.com/kermitt2/grobid/tree/0.7.1
wasabii commented 1 year ago

May be fixed by #416. Awaiting packages then will test.

wasabii commented 1 year ago

@mknezevic Any chance you can send me a built version of this code that you are using? I can't find any sort of binary distribution.

mknezevic commented 1 year ago

Here's the link where I've uploaded the grobid jar files https://t.ly/fmVFY I use onejar in my .NET project and the produced dll grobid.core.dll can also be found at the link.

I also confirm that the problem occurs for x86 with IKVM 8.6.2

I'll post an update to #415

wasabii commented 1 year ago

Uncovered another issue on x86: stdcall name mangling wasn't happening.

wasabii commented 1 year ago

I do believe this is fixed in v8.6.4. I did not test on your specific library, however.