DEV Community

Tamas Padar
Tamas Padar

Posted on • Updated on

Dotnet Core Crl Host

GitHub logo xmegz / clrhost

.Net core crl application host start

.Net Core Runtime Host Start

  • Simple conception howto start .Net Core Runtime from native code

  • C++ part and C# part debugging is also possible.

  • Simple conception for windows to inject dotnet assembly to native exe as resource

  • Just for dotnet 8

Main repository



APIs for hosting and resolve net runtime

Sample Host Example Project

AssemblyLoadBytes trace

    public static unsafe int LoadAssemblyBytes(byte* assembly, nint assemblyByteLength, byte* symbols, nint symbolsByteLength, IntPtr loadContext, IntPtr reserved)
            if (!IsSupported)
                return HostFeatureDisabled
                ArgumentOutOfRangeException.ThrowIfGreaterThan(assemblyByteLength, int.MaxValue);
                ArgumentOutOfRangeException.ThrowIfNotEqual(loadContext, IntPtr.Zero);
                ArgumentOutOfRangeException.ThrowIfNotEqual(reserved, IntPtr.Zero);

                ReadOnlySpan<byte> assemblySpan = new ReadOnlySpan<byte>(assembly, (int)assemblyByteLength);
                ReadOnlySpan<byte> symbolsSpan = default;
                if (symbols != null && symbolsByteLength > 0)
                    symbolsSpan = new ReadOnlySpan<byte>(symbols, (int)symbolsByteLength);

                LoadAssemblyBytesLocal(assemblySpan, symbolsSpan);
            catch (Exception e)
                return e.HResult;

            return 0;

            [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
                Justification = "The same feature switch applies to GetFunctionPointer and this function.

Top comments (1)

xmegz profile image
Tamas Padar

Let's try it