How explore the .NET core assembly using reflection(with Unmanaged API ) from the unmanaged C++ code

62387145 1 Reputation point
2022-04-21T06:19:11.213+00:00

Hi,

I would like to get all the types and methods from the .NET core assembly from the unmanaged C++ code.
Then I want to invoke the method from the unmanaged C++ by hosting the .NET core runtime.

It should be some thing like, I need to load the .NET Core assembly in C++ and expecting to return the __Assembly object, from there I need to explore all the types and methods provided by this assembly. Then execute the method from the C++.

I couldnt find any documentation to get the types and methods of the .NET Core assembly using Unmanaged API. I found docs for .Net framework, but it is failing for the .Net core assembly.

Please let me know, how to get the below information for the .Net Core assembly:

1- How can I explore the .NET core assembly using reflection from the unmanaged C++ code.
2- How can I invoke the .NET Core assembly method from the unmanaged C++ code.
3- Or is there Microsoft documentation for the UnManaged API reference for the .Net Core ?
4- Is there any way/technic to distinguish .Net framework assembly and .Net Core assembly ?

Thanks

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,831 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,187 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 69,656 Reputation points
    2022-04-21T15:53:03.107+00:00

    While doable, your is an advanced project. C# is designed to interact with native apis (C/C++) via parameters marshaling via attributes and p-invoke method. The focus is on C# calling C/C++ methods, and handling callbacks. you want C/C++ to call generic methods that have not been prepped.

    first your C/C++ code must host the .net core dll via the core cli. the car will load the C# code, and will interpret or jit and execute the IL code.

    https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting

    here is the source:

    https://github.com/dotnet/runtime/blob/main/docs/design/features/native-hosting.md

    here is an example of call reflection:

    https://ofstack.com/C++/16317/reflection-calls-the.net-method-in-c++.html

    you might find it easier to write a C# library that implements the reflection features you want and then host this library.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.