0

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

Codes:

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 http://pushtestserver.azurewebsites.net/wns/ 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)

Screenshot:

enter image description here

Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105

1 Answers1

1

The exception is obviously thrown in the web role, before the message is sent to your app.

There is nothing you can do about this the receiving client app. Your code is never executed. The fix has to be applied to the web role. Create your own one or use one that actually works.

mm8
  • 163,881
  • 10
  • 57
  • 88