Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions host/src/FunctionsNetHost/AppLoader/AppLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ internal int RunApplication(string? assemblyPath)

unsafe
{
var parameters = new HostFxr.hostfxr_initialize_parameters
{
size = sizeof(HostFxr.hostfxr_initialize_parameters)
};

var error = HostFxr.Initialize(1, new[] { assemblyPath }, ref parameters, out _hostContextHandle);
var error = HostFxr.Initialize(1, new[] { assemblyPath }, IntPtr.Zero, out _hostContextHandle);

if (_hostContextHandle == IntPtr.Zero)
{
Expand Down Expand Up @@ -95,8 +90,8 @@ private void Dispose(bool disposing)

if (_hostContextHandle != IntPtr.Zero)
{
NativeLibrary.Free(_hostContextHandle);
Logger.LogTrace($"Freed hostcontext handle");
HostFxr.Close(_hostContextHandle);
Logger.LogTrace($"Closed hostcontext handle");
_hostContextHandle = IntPtr.Zero;
}

Expand Down
38 changes: 17 additions & 21 deletions host/src/FunctionsNetHost/AppLoader/HostFxr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,33 @@ public unsafe struct hostfxr_initialize_parameters
public char* dotnet_root;
};

[LibraryImport("hostfxr", EntryPoint = "hostfxr_initialize_for_dotnet_command_line")]
public unsafe static partial int Initialize(
int argc,
[MarshalAs(UnmanagedType.LPArray, ArraySubType =
[LibraryImport("hostfxr", EntryPoint = "hostfxr_initialize_for_dotnet_command_line",
#if OS_LINUX
UnmanagedType.LPStr
StringMarshalling = StringMarshalling.Utf8
#else
UnmanagedType.LPWStr
StringMarshalling = StringMarshalling.Utf16
#endif
)] string[] argv,
ref hostfxr_initialize_parameters parameters,
out IntPtr host_context_handle
);
)]
public unsafe static partial int Initialize(
int argc,
string[] argv,
IntPtr parameters,
out IntPtr host_context_handle
);

[LibraryImport("hostfxr", EntryPoint = "hostfxr_run_app")]
public static partial int Run(IntPtr host_context_handle);

[LibraryImport("hostfxr", EntryPoint = "hostfxr_set_runtime_property_value")]
public static partial int SetAppContextData(IntPtr host_context_handle, [MarshalAs(
#if OS_LINUX
UnmanagedType.LPStr
#else
UnmanagedType.LPWStr
#endif
)] string name, [MarshalAs(
[LibraryImport("hostfxr", EntryPoint = "hostfxr_set_runtime_property_value",
#if OS_LINUX
UnmanagedType.LPStr
StringMarshalling = StringMarshalling.Utf8
#else
UnmanagedType.LPWStr
StringMarshalling = StringMarshalling.Utf16
#endif
)] string value);
)]
public static partial int SetAppContextData(IntPtr host_context_handle, string name, string value);

[LibraryImport("hostfxr", EntryPoint = "hostfxr_close")]
public static partial int Close(IntPtr host_context_handle);
}
}