How to call a .Net core library from native code on Linux?


#1

I want to write a library targeting .Net core and I’d like to run this library inside a Linux daemon. What is the best way of doing this?

If the library was a Mono library, I could have achieved this by:

  1. Writing the daemon in C
  2. Embedding Mono runtime inside the C code
  3. And then loading my managed library.

Is something like this possible under .Net Core?

Update:
As per this article, you can host Core CLR inside a C++ program. But this seems to use COM (IID’s etc) and therefore should work only on Windows. Is there something equivalent for Linux?


#2

This is my biggest question as well.

I have a large quantity of code written in C# and with code generators that target C# as output. Some of that code currently uses Windows Presentation Foundation (XAML). I want to run everything on Windows, OSX and Linux.

The code in question is a user centric security framework ‘The Mathematical Mesh’ that makes using tools like SSH, PGP, S/MIME, etc. with strong security easier than using them at present. [MIT license, see prismproof.org]

My original strategy was to design using C# and then retarget the code generators for C and rewrite. My new strategy is to stay with C#. My objective being to have executables for each platform that run from the command line. Whether these are one executable to run on all three without change or three different .exe files, I don’t care about.

What I do care about is eliminating DLL hell. I use ilmerge to create self contained binaries. Yes, shared libraries for non system code had a point in the 1990s when we counted out RAM in MB. Today I don’t want to have to bother with any DLL that isn’t a system library or driver like thing.

So my new strategy is to rewrite the GUI generator to target GTK#. This is at least supported on all three platforms. It has also given me the opportunity to drop out all the xaml dependencies. My generators are higher level than xaml, it only gets in the way.

One problem I have not yet worked out is how to get the code to work out which platform it is on so that it can change behavior to adapt to other programs on the same platform. The Mesh key manager has to spawn a process to interface with the Thunderbird S/MIME certificate manager because there isn’t actually a documented API. That process is quite a bit different on Windows or Linux because the Thunderbird code works very differently.

So if people are interested in sharing experiences of this approach, please get in contact: phill@hallambaker.com.

As I said, the code for the Mesh is MIT License (i.e. the most open) copyright Comodo Group Inc. The code for the build tools is also MIT License owned by me personally.

Alternatively, if you know of a cross platform GUI library that runs on all three platforms, is accessible from C# and has like documentation that would be better than GTK#, I would be very interested. The problem with GTK# is that Xamarin doesn’t seem to have been maintaining it for several years and so the library is using GTKv2 not v3. Of course if someone wanted to port that library, folk trying to bring PGP, etc. to the masses would be very grateful.


#3

Hi,
you can take a look to coreclr unix


#4

Excellent! Thanks :slight_smile:


.NET Foundation Website | Blog | Projects | Code of Conduct