Forum Xamarin Xamarin.Forms

Exception caught sending update: System.NullReferenceException: Object reference not set to an insta

SreeeeSreeee INMember ✭✭✭✭✭
edited March 2019 in Xamarin.Forms

I added push notification handling codes to my xamarin forms UWP application.


async Task InitRemoteNotificationAsync()
        var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
        if (channel != null)
            channel.PushNotificationReceived += OnPushNotificationReceived;
            Debug.WriteLine($"Received token:{channel.Uri}");

private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)

        if (args.ToastNotification.Content.InnerText != null)
            var msg = args.ToastNotification.Content.InnerText;
            Xamarin.Forms.MessagingCenter.Send<object, string>(this, MyProject.App.NotificationReceivedKey, msg);

I have added null checks in my codes. When I try to push a test notification from the getting the following exception.

Exception caught sending update: System.NullReferenceException: Object reference not set to an instance of an object.
at WebRole1.WNS.WebForm1.PostToWns(String secret, String sid, String uri, String xml, String notificationType, String contentType)
at WebRole1.WNS.WebForm1.btnDiyPush_Click(Object sender, EventArgs e)


  • LandLuLandLu Member, Xamarin Team Xamurai

    I used Azure to test notification on UWP, it works properly. Try to precisely follow this tutorial step by step: Do not forget to associate your app with the store.
    Here is my InitNotificationsAsync using Azure notification hub:

    private async void InitNotificationsAsync()
        var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
        var hub = new NotificationHub("<your hub name>", "<Your DefaultListenSharedAccessSignature connection string>");
        var result = await hub.RegisterNativeAsync(channel.Uri);
        channel.PushNotificationReceived += Channel_PushNotificationReceived;
        //Displays the registration ID so you know it was successful
        if (result.RegistrationId != null)
            var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
            dialog.Commands.Add(new UICommand("OK"));
            await dialog.ShowAsync();

    Moreover, it looks like your issue comes from other parts. Try to remove the OnPushNotificationReceived received method to test your notification.

Sign In or Register to comment.