title: DLLExport in .NET Core 3 for use in an unmanaged C/C++ Code
body: <p>I have found the <a href="https://github.com/3F/DllExport" rel="noreferrer">DllExport</a> Project on GitHub while searching for a way to use C# .NET Core 3 Code from Plain C/C++. My goal is being able to compile the C# to any dynamic library and use it on both Linux or Windows with dlopen (<a href="https://github.com/dlfcn-win32/dlfcn-win32" rel="noreferrer">dlopen for Windows</a>).</p>
  
  <p>C# Library I'm trying to create:</p>
  
  <pre><code>using RGiesecke.DllExport;
  using System;
  
  namespace CSharpPart
  {
      public class Test
      {
          [DllExport]
          public static int _add(int a, int b)
          {
              return a + b;
          }
      }
  }
  </code></pre>
  
  <p>C/C++ Code where I'm trying to Reference the C# Library:</p>
  
  <pre><code>#include "CPartCMake.h"
      #include "dlfcn.h"
      #include "cstring"
  
      using namespace std;
  
      int main()
      {
          const char* pemodule = "path_to_dll\\CSharpPart.dll";
          void* handle = dlopen(pemodule, RTLD_NOW);
  
          typedef int(_cdecl* _add)(int a, int b);
          _add pAdd = (_add)dlsym(handle, "_add");
          cout &lt;&lt; pAdd(5, 7);
          return 0;
  
      }
  </code></pre>
  
  <p>The Call to dlopen returns a non NULL handle which I guess means that the Library itself can be opened. dlsym return a NULL. When viewing the C# DLL through <a href="https://www.nirsoft.net/utils/dll_export_viewer.html" rel="noreferrer">DLL Export Viewer</a> it can be confirmed that the DLL doesn't contain the _add entry.</p>
  
  <p>I tried Wrapping the C# project in an C++/CLI Project like proposed <a href="https://stackoverflow.com/a/1827589/5853383">here</a> but it doesn't seems to work with .NET Core.</p>
  
  <p>I read there is also a possibility with using COM interop but I didn't really understood what it is about and I'm not sure if it would work cross-platform like.</p>
  
  <p>I'm afraid that DLLExport just isn't yet compatible with .NET Core as well. Is there any way of achieving my goal like I described it?</p>