A call to PInvoke function has unbalanced the stack. This is likely because the managed PInvoke .. (.NET 4)

Add this along with dll import.

, CallingConvention = CallingConvention.Cdecl)]

As taken from here.

Platform invoke

To improve performance in interoperability with unmanaged code, incorrect calling conventions in a platform invoke now cause the application to fail. In previous versions, the marshaling layer resolved these errors up the stack.

Debugging your applications in Microsoft Visual Studio 2010 will alert you to these errors so you can correct them. If you have binaries that cannot be updated, you can include the element in your application's configuration file to enable calling errors to be resolved up the stack as in earlier versions. However, this may affect the performance of your application.

Tags:

C#

.Net

Pinvoke