Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Bug] iOS XF 5.0-pre1 crash with CollectionView when using EmptyView #12374

@beeradmoore

Description

@beeradmoore

Description

While testing XF 5.0-pre1 I came across some NRE of the DefaultRenderer object when using CollectionView and adding an EmptyView. This only appears to be for iOS, Android does not crash with the below samples.

Steps to Reproduce

  1. Add a CollectionView
  2. Add an EmptyView
  3. Add a way to add items to the CollectionView (I have used a bound ObservableCollection)
  4. From seeing the EmptyView (either from launch or from removing existing items) try add new items
  5. Crash

Steps to Reproduce with reproduction sample below

  1. Launch the app on iOS simulator (did not test physical device)
  2. Click each item to remove them and view the EmptyView.
  3. Pull to refresh to add new items or click the AddItems button.
  4. Crash.
  5. Open MainPage.xaml, remove comments around CollectionView.EmptyViewTemplate
  6. Repeat steps 1-3.
  7. No crash.

Expected Behavior

New items get added to the CollectionView

Actual Behavior

Crash with the following

Unhandled Exception:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'DefaultRenderer'.
  at Foundation.NSObject.get_SuperHandle () [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSObject2.cs:394 
  at UIKit.UIView.set_Frame (CoreGraphics.CGRect value) [0x00024] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIView.g.cs:3733 
  at Xamarin.Forms.Platform.iOS.ItemsViewController`1[TItemsView].LayoutEmptyView () [0x0000f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewController.cs:300 
  at Xamarin.Forms.Platform.iOS.ItemsViewController`1[TItemsView].ViewWillLayoutSubviews () [0x0003a] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewController.cs:163 
  at Xamarin.Forms.Platform.iOS.StructuredItemsViewController`1[TItemsView].ViewWillLayoutSubviews () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\StructuredItemsViewController.cs:78 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:86 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:65 
  at EmptyViewTest.iOS.Application.Main (System.String[] args) [0x00001] in /Users/bradmoore/Projects/EmptyViewTest/EmptyViewTest.iOS/Main.cs:17

Basic Information

  • Version with issue: 5.0.0.1487-pre1
  • Last known good version: 4.8.0.1451
  • IDE: Visual Studio Community 2019 for Mac, Version 8.7.8 (build 4)
  • Platform Target Frameworks:
    • iOS: Xamarin.iOS 14.0.0.0
  • Nuget Packages: Xamarin.Forms 4.8.0.1451, 5.0.0.1487-pre1. Xamarin.Essentials (although not used) 1.6.0-pre2.

Reproduction Link

See the attached sample which will crash when you follow the steps in the main description.

EmptyViewTest.zip

Workaround

Move any UI code from EmptyView to EmptyViewTemplate, set just an empty object in EmptyView. From reading the (documentation)[https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview/emptyview], I don't believe this is how EmptyView and EmptyViewTemplate was intended to be used.

<CollectionView.EmptyView>
    <BoxView />
</CollectionView.EmptyView>

<CollectionView.EmptyViewTemplate>
    <DataTemplate>
        <Grid>
            <Label Text="Empty Template View" HorizontalOptions="Center" VerticalOptions="Center" />
        </Grid>
    </DataTemplate>
</CollectionView.EmptyViewTemplate>

Metadata

Metadata

Assignees

Labels

a/collectionviewblockerIssue blocks next stable release. Prioritize fixing and reviewing this issue.e/2 🕑2i/highCompletely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less ofteni/regressionin-progressThis issue has an associated pull request that may resolve it!p/iOS 🍎t/bug 🐛

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions