PInvokeStackImbalance exception when targetting .NET Framework (Windows)
When using the Highs.Native 1.7.1 nuget package in a .NET Framework application (pre-.NET Core/5/6/7/8, Windows only), a PInvokeStackImbalance exception is raised when calling methods such as passLp and readModel.
In highs_csharp_api.cs, all native methods are decorated as follows: [DllImport(highslibname)].
However, as described here:
The default value for the CallingConvention field is Winapi, which in turn defaults to StdCall convention on Windows, and Cdecl on all other platforms.
On later versions like .NET 8 on Windows, the exception does not occur because it seems to be no longer implemented (see https://learn.microsoft.com/en-us/dotnet/framework/debug-trace-profile/pinvokestackimbalance-mda), but the problem may still cause applications to become unstable.
Could the DllImport-attribute receive an explicit CallingConvention.Cdecl to be compatible with all platforms and target frameworks?
Could you please give us more details about your use case which is triggering the error? Which .NET version, particularly, on Windows, leads to the crash? Which Windows version are you using? Do you have a x32 or an x64 build?
Hello @galabovaa , I can reproduce the error on Windows 11, .NET Framework 4.7.2 with a 32-bit build. The same setup with a 64-bit build does work fine.