Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 910
Aman Avatar asked Nov 30 '25 08:11

Aman


1 Answers

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.

like image 151
Danial Avatar answered Dec 01 '25 21:12

Danial