C
C#2mo ago
kianyuen

Managed Debugging Assistant 'PInvokeStackImbalance'

I have a dll file that is originally used in a .NET Framework 3.5 Project. I am trying to port that module to .NET Framework 4.8, but Managed Debugging Assistant keeps throwing the error mentioned above. Turning off the MDA allowed the program to run, but is that recommended? This is how I import a function from the dll file
[DllImport("CsnPrinterLibs.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern uint Port_EnumCOM(byte[] buffer, int length);
[DllImport("CsnPrinterLibs.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern uint Port_EnumCOM(byte[] buffer, int length);
6 Replies
reflectronic
reflectronic2mo ago
no, it suggests the p/invoke is declared incorrectly can you show the declaration for Port_EnumCOM in this unmanaged library you are using
kianyuen
kianyuen2mo ago
I have the one from the header file:
CSNPRINTERLLIBS size_t __stdcall Port_EnumCOM(char *buffer, size_t length);
CSNPRINTERLLIBS size_t __stdcall Port_EnumCOM(char *buffer, size_t length);
The header's comments is kinda like a doc on its own, but it was written in Chinese or something, the characters are all messed up.
reflectronic
reflectronic2mo ago
well, it says __stdcall, so CallingConvention.Cdecl is not correct, it should be CallingConvention.StdCall and, since these are size_t, those uint and int should be IntPtr
kianyuen
kianyuen2mo ago
I did try stdcall actually, but yeah. They also simply use string for char*. This dll import code was given to me by the ones that sold the hardware. Guess I will try to correct it some time later.
Petris
Petris2mo ago
ClangSharpPInvokeGenerator 18.1.0
ClangSharp are strongly-typed safe Clang bindings written in C# for .NET and Mono, tested on Linux and Windows.
kianyuen
kianyuen2mo ago
Thanks, too bad I got a problem with running it on dotnet console. Will try again later.
Want results from more Discord servers?
Add your server