diff --git a/host/src/FunctionsNetHost/Native/NativeExports.cs b/host/src/FunctionsNetHost/Native/NativeExports.cs
index 2d44f3015..f5ef01554 100644
--- a/host/src/FunctionsNetHost/Native/NativeExports.cs
+++ b/host/src/FunctionsNetHost/Native/NativeExports.cs
@@ -10,24 +10,10 @@ namespace FunctionsNetHost
public static class NativeExports
{
[UnmanagedCallersOnly(EntryPoint = "get_application_properties")]
- public static int GetApplicationProperties(NativeHostData nativeHostData)
+ public static unsafe int GetApplicationProperties(NativeHostData* nativeHostData)
{
Logger.LogTrace("NativeExports.GetApplicationProperties method invoked.");
-
- try
- {
- var nativeHostApplication = NativeHostApplication.Instance;
- GCHandle gch = GCHandle.Alloc(nativeHostApplication, GCHandleType.Pinned);
- IntPtr pNativeApplication = gch.AddrOfPinnedObject();
- nativeHostData.PNativeApplication = pNativeApplication;
-
- return 1;
- }
- catch (Exception ex)
- {
- Logger.Log($"Error in NativeExports.GetApplicationProperties: {ex}");
- return 0;
- }
+ return 1;
}
[UnmanagedCallersOnly(EntryPoint = "register_callbacks")]
diff --git a/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec b/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec
index 0f198f5a2..5e5c77c4e 100644
--- a/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec
+++ b/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec
@@ -4,7 +4,7 @@
Microsoft.Azure.Functions.DotNetIsolatedNativeHost
Microsoft Azure Functions dotnet-isolated native host
dotnet-isolated azure-functions azure
- 1.0.2
+ 1.0.3
Microsoft
Microsoft
https://github.com/Azure/azure-functions-dotnet-worker
diff --git a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeHost.cs b/src/DotNetWorker.Grpc/NativeHostIntegration/NativeHost.cs
deleted file mode 100644
index 2b16e7d6a..000000000
--- a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeHost.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the MIT License. See License.txt in the project root for license information.
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace Microsoft.Azure.Functions.Worker.Grpc.NativeHostIntegration
-{
- [StructLayout(LayoutKind.Sequential)]
- internal struct NativeHost
- {
- public IntPtr pNativeApplication;
- }
-}
diff --git a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeMethods.cs b/src/DotNetWorker.Grpc/NativeHostIntegration/NativeMethods.cs
index 390d45efe..ebaeea44c 100644
--- a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeMethods.cs
+++ b/src/DotNetWorker.Grpc/NativeHostIntegration/NativeMethods.cs
@@ -17,38 +17,27 @@ static NativeMethods()
NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, ImportResolver);
}
- public static NativeHost GetNativeHostData()
- {
- var result = get_application_properties(out var hostData);
- if (result == 1)
- {
- return hostData;
- }
-
- throw new InvalidOperationException($"Invalid result returned from get_application_properties: {result}");
- }
-
- public static void RegisterCallbacks(NativeSafeHandle nativeApplication,
+ public static void RegisterCallbacks(
delegate* unmanaged requestCallback,
IntPtr grpcHandler)
{
- _ = register_callbacks(nativeApplication, requestCallback, grpcHandler);
+ _ = register_callbacks(IntPtr.Zero, requestCallback, grpcHandler);
}
- public static void SendStreamingMessage(NativeSafeHandle nativeApplication, StreamingMessage streamingMessage)
+ public static void SendStreamingMessage(StreamingMessage streamingMessage)
{
byte[] bytes = streamingMessage.ToByteArray();
- _ = send_streaming_message(nativeApplication, bytes, bytes.Length);
+ fixed (byte* ptr = bytes)
+ {
+ _ = send_streaming_message(IntPtr.Zero, ptr, bytes.Length);
+ }
}
- [DllImport(NativeWorkerDll, CharSet = CharSet.Auto)]
- private static extern int get_application_properties(out NativeHost hostData);
-
- [DllImport(NativeWorkerDll, CharSet = CharSet.Auto)]
- private static extern int send_streaming_message(NativeSafeHandle pInProcessApplication, byte[] streamingMessage, int streamingMessageSize);
+ [DllImport(NativeWorkerDll)]
+ private static extern int send_streaming_message(IntPtr pInProcessApplication, byte* streamingMessage, int streamingMessageSize);
- [DllImport(NativeWorkerDll, CharSet = CharSet.Auto)]
- private static extern unsafe int register_callbacks(NativeSafeHandle pInProcessApplication,
+ [DllImport(NativeWorkerDll)]
+ private static extern unsafe int register_callbacks(IntPtr pInProcessApplication,
delegate* unmanaged requestCallback,
IntPtr grpcHandler);
diff --git a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClient.cs b/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClient.cs
index aa7f39984..14f32035c 100644
--- a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClient.cs
+++ b/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClient.cs
@@ -15,17 +15,15 @@ internal class NativeWorkerClient : IWorkerClient
private readonly IMessageProcessor _messageProcessor;
private readonly ChannelReader _outputChannelReader;
private readonly ChannelWriter _outputChannelWriter;
- private readonly NativeSafeHandle _application;
private GCHandle _gcHandle;
private readonly Channel _inbound = Channel.CreateUnbounded();
- public NativeWorkerClient(IMessageProcessor messageProcessor, GrpcHostChannel outputChannel, NativeHost nativeHostData)
+ public NativeWorkerClient(IMessageProcessor messageProcessor, GrpcHostChannel outputChannel)
{
_messageProcessor = messageProcessor;
_outputChannelReader = outputChannel.Channel.Reader;
_outputChannelWriter = outputChannel.Channel.Writer;
- _application = new NativeSafeHandle(nativeHostData.pNativeApplication);
}
public Task StartAsync(CancellationToken cancellationToken)
@@ -37,7 +35,7 @@ public Task StartAsync(CancellationToken cancellationToken)
public unsafe void Start()
{
_gcHandle = GCHandle.Alloc(this);
- NativeMethods.RegisterCallbacks(_application, &HandleRequest, (IntPtr)_gcHandle);
+ NativeMethods.RegisterCallbacks(&HandleRequest, (IntPtr)_gcHandle);
_ = ProcessInbound();
_ = ProcessOutbound();
@@ -55,7 +53,7 @@ private async Task ProcessOutbound()
{
await foreach (StreamingMessage msg in _outputChannelReader.ReadAllAsync())
{
- NativeMethods.SendStreamingMessage(_application, msg);
+ NativeMethods.SendStreamingMessage(msg);
}
}
diff --git a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClientFactory.cs b/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClientFactory.cs
index 75c40e3fe..20ce548db 100644
--- a/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClientFactory.cs
+++ b/src/DotNetWorker.Grpc/NativeHostIntegration/NativeWorkerClientFactory.cs
@@ -14,8 +14,7 @@ public NativeWorkerClientFactory(GrpcHostChannel hostChannel)
public IWorkerClient CreateClient(IMessageProcessor messageProcessor)
{
- var nativeHostData = NativeMethods.GetNativeHostData();
- return new NativeWorkerClient(messageProcessor, _hostChannel, nativeHostData);
+ return new NativeWorkerClient(messageProcessor, _hostChannel);
}
}
}