我想将 UWP 应用程序与 .NET 6 应用程序通信。根据我的研究,我可以通过 gRPC 作为 IPC 机制来完成。我遵循了这个示例应用程序。这个应用程序在调试模式下运行,但在发布版本中我遇到了异常。这是我发生异常的代码片段。
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
try
{
// Just to get rid of the async warning.
await Task.Delay(0);
WriteLog("Transporter Room Panel Startup.");
WriteLog("- Openening a channel.");
_channel = new Channel("localhost:50051", ChannelCredentials.Insecure);
// Optional: deadline.
// Uncomment the delay in Server Program.cs to test this.
// await _channel.ConnectAsync(deadline: DateTime.UtcNow.AddSeconds(2));
WriteLog("- Channel open.");
_client = new TransporterClient(_channel);
}
catch (Exception ex)
{
string exc = ex.ToString();
WriteLog("Exception: " + exc);
}
}
我在执行这行代码时遇到异常
_channel = new Channel("localhost:50051", ChannelCredentials.Insecure);
在发布版本中,但它在调试模式下工作正常。
异常调用栈为:
System.ArgumentNullException: Value cannot be null.
Parameter name: path1
at System.IO.Path.Combine(String, String) + 0x50
at Grpc.Core.Internal.NativeExtension.LoadNativeMethodsUsingExplicitLoad() + 0x69
at Grpc.Core.Internal.NativeExtension.LoadNativeMethods() + 0xd3
at Grpc.Core.Internal.NativeExtension..ctor() + 0x12
at Grpc.Core.Internal.NativeExtension.Get() + 0x6a
at Grpc.Core.GrpcEnvironment.GrpcNativeInit() + 0x68
at Grpc.Core.GrpcEnvironment..ctor() + 0x97
at Grpc.Core.GrpcEnvironment.AddRef() + 0x7d
at Grpc.Core.Channel..ctor(String, ChannelCredentials, IEnumerable`1) + 0x102
at XamlBrewer.Uwp.Grpc.Client.MainPage.<MainPage_Loaded>d__4.MoveNext() + 0xef
上述异常的解决方法是什么?
我想在不使用 App Service 的情况下从 UWP 到 .NET 6 App 进行通信。