1

I have some C# library - for the sake of simplicity say it has such code:

namespace space1
{
    public class Class1
    {
        public static void Method1()
        {
            Console.WriteLine("method1");
        }

        public static string Method2(string str1, string str2)
        {
            return str1 + " " + str2;
        }
    }
}

And I want to call it from C++ code somehow. I've been looking around and have tried solutions but non of them were applicable for my case for following reasons:

  • Use of Windows API - the program will run exclusively on Linux
  • Use of Visual Studio libraries - the C++ program is to be compiled using gcc or g++
  • No changes to the C# library can be made

So far I have not find anything that would meet all requirements. Rewriting the library is out of the question (there could be some wrapper library thou). I would also like to avoid having additional program - like C++ code starting a process and feeding arguments via stdin, pipes or TCP.

Miku
  • 567
  • 6
  • 15
  • `C#` cannot run on linux if you do not change it and compile as `.netcore` period. The only other possible solution is to run it in a hosted process on a windows machine and TCP to it. – Franck Jun 05 '20 at 12:19
  • The library shown has been compiled and tested on `Mono` runtime so, yeah - I know that – Miku Jun 05 '20 at 12:23
  • You would need to use the [Hosting apis](https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting) I can't turn this into an answer as I don't have enough experience with them to give pointers. – Mgetz Jun 05 '20 at 12:34
  • This is now possible with .NET 5.0, please see my answer here: https://stackoverflow.com/a/63203205/4669135 – Gabriel Devillers Aug 01 '20 at 08:23

0 Answers0