sherpa-onnx icon indicating copy to clipboard operation
sherpa-onnx copied to clipboard

Exception Thrown When Debugging C# Windows x86 Application in Visual Studio Due to Calling Convention Mismatch (stdcall vs cdecl)

Open ajon88 opened this issue 9 months ago • 2 comments

Exception: Managed Debugging Assistant 'PInvokeStackImbalance' Message=Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'sherpa-onnx!SherpaOnnx.KeywordSpotter::SherpaOnnxCreateKeywordSpotter' 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.'

Description: When debugging a C# application targeting the Windows x86 architecture in Visual Studio , an exception is thrown due to a mismatch in calling conventions between the following components: C# Assembly : sherpa-onnx.dll (uses stdcall calling convention) Win32 DLL : sherpa-onnx-c-api.dll (uses cdecl calling convention) The issue arises because the calling conventions (stdcall vs cdecl) are not compatible, leading to runtime errors during debugging.

Steps to Reproduce: Build and run the C# application targeting Windows x86 architecture . Ensure the application references sherpa-onnx.dll, which internally calls functions from sherpa-onnx-c-api.dll. Start debugging the application in Visual Studio (using the debugger). Observe the exception being thrown.

ajon88 avatar Feb 17 '25 01:02 ajon88