Xamarin.Mac - Send notification

153 Views Asked by At

I'm trying to send push notification with Azure Notification Hub and Xamarin.Mac. I have this error, and I don't know why. Someone can help me to deal with it ?

The error:

System.TypeInitializationException: The type initializer for 'TimerManager' threw an exception. ---> System.EntryPointNotFoundException: CreateWaitableTimer

My code:

 private static async void SendNotificationAsync()
 {
     NotificationHubClient hub = NotificationHubClient
         .CreateClientFromConnectionString("<connection string>", "<hub name>");
     string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
         "<wp:Notification xmlns:wp=\"WPNotification\">" +
           "<wp:Toast>" +
               "<wp:Text1>Content</wp:Text1>" +
           "</wp:Toast> " +
         "</wp:Notification>";
     await hub.SendMpnsNativeNotificationAsync(toast);
 }
1

There are 1 best solutions below

1
On BEST ANSWER

There are several areas of that library that are Windows Desktop specific and are not available on Mono, UWP, Win10 IoT, etc.. (Items like CreateWaitableTimer are native Windows Desktop API calls).

Azure has a number of different clients and libraries, the most "portable" is the REST api, sending a MPNS Native Notification involves performing a POST to:

https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/?api-version=2015-01

The docs show the content and headers required: