C# – Is it possible to call a shared library (.so) on linux platform from .NET core

.net coreccross platformnetshared-libraries

I understand that aim of the .NET core is for cross platform development, but I am looking for backward compatibility. If I have a linux library available (maybe, legacy) and I want its functions to be called from .NET core application for linux platform. Is it possible?

I am not talking about ASP.NET core, I need it for a desktop application.

Best Answer

Yes: https://github.com/dotnet/corefx/issues/343

That being said, I'll admit to not having actually tried it yet. I have used this a far bit on Mono, for what it's worth, and it's definitely worth reading their documentation on this: http://www.mono-project.com/docs/advanced/pinvoke/ ... because .net core seems to take much the same approach (eg: leave off the file extension for the p-invoked library, so the system can take care of linking to the right version etc...)

Eg how bits of .net core itself do this:

const string LIBC = "libc";

[DllImport(LIBC, EntryPoint = "getenv")]
private static extern IntPtr getenv_core(string name);

https://github.com/dotnet/corefx/blob/79d44f202e4b6d000ca6c6885a24549a55db38f1/src/System.Console/src/Interop/Interop.manual.Unix.cs