Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PInvokeStackImbalance exception when targetting .NET Framework (Windows) #1822

Open
TheCrustyCrab opened this issue Jun 30, 2024 · 0 comments
Assignees

Comments

@TheCrustyCrab
Copy link

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?

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

No branches or pull requests

3 participants