简体   繁体   中英

UWP app is crashing due to Xamarin.CarouselView in Xamarin UWP project

Following is the error:

System.ArgumentException: Delegate to an instance method cannot have null 'this'.
   at System.MulticastDelegate.ThrowNullThisInDelegateToInstance()
   at CarouselView.FormsPlugin.UWP.CarouselViewRenderer.FlipView_Loaded(Object sender, RoutedEventArgs e)

This is an error in CarouselView control UWP renderer which is registered in library issues: https://github.com/alexrainman/CarouselView/issues/526 .

In my case, I got this crash in an admin app which is part of a solution developed exclusived by me. What makes me curious about this was that end user app don't present this issue. All the solution was coded by me, using the same tecnhologies, libraries, etc etc.

So I started to decompose admin app to understand the crash by comparing it against end user app code. I reached the conclusion that crash is caused at OnAppearing by a clear call over the list which is set as control's ItemSource.

public ProductPage(string productId)
{
    InitializeComponent();

    this.productId = productId;

    this.products = new ObservableCollection<ProductGalleryDTO>();
    this.ProductGallery.ItemsSource = this.products;
}

protected override void OnAppearing()
{
    base.OnAppearing();

    // Note: this causes the issue in my case
    //this.products.Clear();

    this.GetProductDetails();
}

Probably the repro step for your crash are different since this should be some unexpected state which UWP renderer is not able to handle.

Furthermore, I started to use this library few years ago when there was no similar control in Xamarin.Forms. Nowadays we have CarouselView: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/carouselview/

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