简体   繁体   中英

System.MemberAccessException: Cannot create an instance of UserNotifications.UNNotificationTrigger because it is an abstract class

I am using the latest notification framework UNUserNotificationCenter for scheduling local notifications.

I am sharing some code snippets where I refer to trigger/access trigger. Do not read this sequentially. It is just code snippets where I read or modift trigger

var trigger = UNCalendarNotificationTrigger.CreateTrigger(notification.ScheduledTime.DateTimeToNSDateComponents(), false);

trigger.DateComponents.Hour = trigger.DateComponents.Hour + 7;

var trigger = (UNCalendarNotificationTrigger)(notification.Trigger);

This works without any compilation error and the notification also worked. We have this code in the app store from past few months. Off late we are seeing a crash with the below message . I haven't referenced UNNotificationTrigger in my code. BTW this is xamarin IOS app.

System.MemberAccessException: Cannot create an instance of UserNotifications.UNNotificationTrigger because it is an abstract class

This is a problem in Xamarin.iOS that we are looking to fix.

What is going on is that the trigger vanishes or gets collected at some point, and it is later resurfaced, and the resurfacing does not know about the actual hidden concrete implementation for this, so you get the above message.

The best workaround for now is to keep a pointer to the trigger alive in managed code, thus ensuring that the resurfacing is never triggered.

We are tracking this here:

https://github.com/xamarin/xamarin-macios/issues/3935#issuecomment-381200652

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM