`coreclr_create_delegate` doesn't work when called from C++ code on Mac

0

I need to call method declared in C# library from C++ code on Mac. I am using .Net Core framework 2.0.x (2.0.3, 2.0.4).

To make it work, I call coreclr_initialize which runs successfully and returns 0. I then call coreclr_create_delegate by passing required arguments as given below:

auto no_del = []( auto x ) { (void)(x); };
auto csharp_runIt = std::unique_ptr<csharp_runIt_t, decltype(no_del)>(nullptr, no_del);

int status = coreclr_create_delegate (
                                          hostHandle,
                                          domainId,
                                          assemblyName.c_str(),
                                          entryPointType.c_str(),
                                          entryPointName.c_str(),
                                          reinterpret_cast<void**>(&csharp_runIt)
                                          );

Here, hostHandle and domainId are received from coreclr_initialize. Rest of the values are: assemblyName (dll name), entryPointType (class name) and entryPointName (function name). Running it returns negative value with hex code: 0x80070002.

I am also passing library name, class name and method name as arguments. As not many have tried it, not much help is available online.

c#
c++
macos
.net-core
asked on Stack Overflow Jan 3, 2018 by Aman • edited Jan 3, 2018 by Aman

2 Answers

0

Alright so I got what was wrong. The .NetCore library was under namespace and thus the coreclr_create_delegate was not getting created. So either don't use namespace or use it while calling in C++ delegate too.

The .Netcore code should be something like:

//namespace samplelibrary //This was causing error
//{
    public class SampleClass
    {
        public static string MyFunc()
        {
            return "arrived";
        }
    }
//}
answered on Stack Overflow Jan 3, 2018 by Aman • edited Jan 9, 2018 by Aman
0

You need to specify the fully qualified name for that class if it is not in the global namespace. For instance, you need to set entryPointType to samplelibrary.SampleClass here.

answered on Stack Overflow May 31, 2018 by Danial

User contributions licensed under CC BY-SA 3.0