When including the C# wrapper in a .NET Framework library a runtime error PInvokeStackImbalance occurs whenever a P/Invoke call is being made.
The error is apparently due to improper P/Invoke calling conventions, where for .NET Framework the convention defaults to WinApi/StdCall instead of the correct CDecl convention (see this StackOverflow answer).
To circumvent this problem, for any platform regardless of calling convention default, my suggestion is to explicitly set the calling convention in all [DllImport] decorations, e.g. like this:
When including the C# wrapper in a .NET Framework library a runtime error PInvokeStackImbalance occurs whenever a P/Invoke call is being made.
The error is apparently due to improper P/Invoke calling conventions, where for .NET Framework the convention defaults to
WinApi
/StdCall
instead of the correctCDecl
convention (see this StackOverflow answer).To circumvent this problem, for any platform regardless of calling convention default, my suggestion is to explicitly set the calling convention in all
[DllImport]
decorations, e.g. like this: