Xamarin.forms 使用Prism和SignalR导航到Xamarin表单中的另一页时出现异常

Xamarin.forms 使用Prism和SignalR导航到Xamarin表单中的另一页时出现异常,xamarin.forms,prism,signalr.client,Xamarin.forms,Prism,Signalr.client,我有一个使用Prism的Xamarin Forms PCL应用程序。此外,该应用程序是一个信号器客户端。在主页面(脚手架创建的主页面)中,我设置了信号器: public MainPageViewModel(INavigationService navigationService) { this.navigationService = navigationService; SetupSignalr(); } private async voi

我有一个使用Prism的Xamarin Forms PCL应用程序。此外,该应用程序是一个信号器客户端。在主页面(脚手架创建的主页面)中,我设置了信号器:

 public MainPageViewModel(INavigationService navigationService)
    {
        this.navigationService = navigationService;

        SetupSignalr();
    }

 private async void SetupSignalr()
    {
        hubConnection = new HubConnection("http://mypc:15816/");
        hubProxy = hubConnection.CreateHubProxy("SignatureCaptureHub");
        hubProxy.On<string>("ShowSignatureControl",  receiptText =>  NavigateToSignaturePad(receiptText));
        await hubConnection.Start();

        await hubProxy.Invoke("JoinGroup", "Group1234");
    }
如前所述,当收到信号器消息时,我收到以下异常:

在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中 [0x0000c]英寸:0英寸 Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference实例,Java.Interop.JniMethodInfo 方法)[0x00068]位于:0处 Android.Runtime.JNIEnv.CallVoidMethod(System.IntPtr jobject, System.IntPtr jmethod)[0x0000e]在 :0 at 中的Android.Views.IMenuInvoker.Clear()[0x00033] :0 at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.UpdateMenu ()[0x0005a]英寸 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:682 在 Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.ToolbarTrackerOnCollectionChanged (System.Object发送方,System.EventArgs EventArgs)[0x00000]位于 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:668 位于Xamarin.Forms.Internals.ToolbarTracker.EmitCollectionChanged() [0x00008]英寸 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Internals\ToolbarTracker.cs:60 在Xamarin.Forms.Internals.ToolbarTracker.OnPropertyChanged (System.Object发送方,System.ComponentModel.PropertyChangedEventArgs 中的propertyChangedEventArgs)[0x00052] C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Internals\ToolbarTracker.cs:130 at(包装器委托调用) :invoke_void_object_PropertyChangedEventArgs (对象,System.ComponentModel.PropertyChangedEventArgs)位于 Xamarin.Forms.BindableObject.OnPropertyChanged(System.String 中的propertyName)[0x0000a] C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:137 在Xamarin.Forms.Element.OnPropertyChanged(System.String)处 中的propertyName)[0x00000] C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:379 位于Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty属性, Xamarin.Forms.BindableObject+BindablePropertyContext上下文, System.Object值,System.Boolean当前应用, Xamarin.Forms.BindableObject+SetValueFlags属性,System.Boolean 静音)[0x000f4]输入 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:581 位于Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty属性,System.Object值, Xamarin.Forms.BindableObject+SetValueFlags属性, Xamarin.Forms.BindableObject+SetValuePrivateFlags(私有属性) [0x0014b]英寸 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:378 位于Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty属性,System.Object值, System.Boolean fromStyle,System.Boolean checkAccess)[0x0005f]输入 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:531 位于Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindablePropertyKey propertyKey,System.Object值) [0x0000e]英寸 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:91 在Xamarin.Forms.NavigationPage.set_CurrentPage(Xamarin.Forms.Page 值)[0x00000]英寸 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationPage.cs:85 位于Xamarin.Forms.NavigationPage.PushPage(Xamarin.Forms.Page) [0x00011]英寸 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationPage.cs:371 在Xamarin.Forms.NavigationPage+d_u90.MoveNext()中 [0x0002f]英寸 C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationPage.cs:350

---来自引发异常的上一个位置的堆栈结束跟踪---在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c]英寸:0英寸 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess (System.Threading.Tasks.Task任务)[0x0003e]中的 :0 at System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification 中的(System.Threading.Tasks.Task任务)[0x00028] :0 at System.Runtime.CompilerServices.TaskWaiter.ValidateEnd 中的(System.Threading.Tasks.Task任务)[0x00008] :0 at 中的System.Runtime.CompilerServices.TaskAwaiter.GetResult()[0x00000] :0 at 中的Xamarin.Forms.NavigationPage+d_u48.MoveNext()[0x0017f] C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationPage.cs:182

---来自引发异常的上一个位置的堆栈结束跟踪---在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c]英寸:0英寸 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess (System.Threading.Tasks.Task任务)[0x0003e]中的 :0 at System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification 中的(System.Threading.Tasks.Task任务)[0x00028] :0 at System.Runtime.CompilerServices.TaskWaiter.ValidateEnd 中的(System.Threading.Tasks.Task任务)[0x00008] :0 at 中的System.Runtime.CompilerServices.TaskAwaiter.GetResult()[0x00000] :0 at Prism.Navigation.PageNavigationService+d_u31.MoveNext() [0x00139]输入:0 ---来自引发异常的上一个位置的堆栈结束跟踪---在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c]英寸:0英寸 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess (System.Threading.Tasks.Task任务)[0x0003e]中的 :0 at System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification 中的(System.Threading.Tasks.Task任务)[0x00028] :0 at System.Runtime.CompilerServices.TaskWaiter.ValidateEnd 中的(System.Threading.Tasks.Task任务)[0x00008] :0 at System.Runtime.CompilerServices.TaskAwaiter.GetRe
private async void NavigateToSignaturePad(string receiptText)
    {
        System.Diagnostics.Debug.WriteLine("Got a ShowSignatureControl event!");

        Title = "Got a ShowSignatureControl event!";

        try
        {
            //Device.BeginInvokeOnMainThread(async () => await navigationService.NavigateAsync("SignatureCapturePage"));
            await navigationService.NavigateAsync("SignatureCapturePage");
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message);
        }
    }
 public MainPageViewModel(INavigationService navigationService)
    {
        this.navigationService = navigationService;

        SetupSignalr();
    }

    private async void SetupSignalr()
    {
        hubConnection = new HubConnection("http://mypc:15816/");
        hubProxy = hubConnection.CreateHubProxy("SignatureCaptureHub");
        hubProxy.On<string>("ShowSignatureControl",  receiptText =>  NavigateToSignaturePad(receiptText));
        await hubConnection.Start();

        await hubProxy.Invoke("JoinGroup", "Group1234");
    }

    private void NavigateToSignaturePad(string receiptText)
    {
        System.Diagnostics.Debug.WriteLine("Got a ShowSignatureControl event!");

        var navigationParameters = new NavigationParameters
        {
            { "receiptText", receiptText }
        };
        Device.BeginInvokeOnMainThread(() => navigationService.NavigateAsync(nameof(SignatureCapturePage), navigationParameters));
    }