P-Invoke in .net core with Linux

Elshan picture Elshan · Jul 5, 2016 · Viewed 11.3k times · Source

Is there way to implement P/Invoke (dllimport) in .NET Core on Linux ?

Example :

I have C++ MyLib.dll compiled with .net framework.

If it is possible to use like this or it's not support to call native win api with linux using .net-core ?

[DllImport("MyLib.dll", CallingConvention = CallingConvention.StdCall)]
internal static extern long NativeMethod();

Answer

Eric Mellino picture Eric Mellino · Jul 5, 2016

PInvoke is certainly supported (that is how all of the code that interfaces with the OS works), but not in the specific case you listed. You cannot PInvoke to a win32 binary on Linux, unless you have somehow built a function-compatible version of it for Linux yourself. More realistically, you need to find a Linux function from some other system binary which exposes similar functionality, and then use that instead.