Xamarin.forms: [Bug] CollectionView attempt to prepare layout

Created on 13 Dec 2019  路  21Comments  路  Source: xamarin/Xamarin.Forms

Description

2019-12-13 15:59:25.480329+0000 .iOS[3842:190375] [CollectionView] An attempt to prepare a layout while a prepareLayout call was already in progress (i.e. reentrant call) has been ignored. Please file a bug. UICollectionView instance is (; layer = ; contentOffset: {0, 0}; contentSize: {1, 0}; adjustedContentInset: {0, 0, 0, 0}; layout: ; dataSource: >)

Steps to Reproduce



    1. 2.
  1. 3.

Expected Behavior

Actual Behavior

Basic Information

  • Version with issue: 4.4.0 latest stable
  • Last known good version:
  • IDE: VSMac
  • Platform Target Frameworks:

    • iOS: 11

  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Screenshots

Reproduction Link

collectionview high high impact mobcat iOS 馃崕 bug

All 21 comments

Could you please attach a zipped reproduction solution and expand on the actual and expected behavior?

Hi we would need more info to understand this issue.

@bcaceiro Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you!

I'm having the same issue on iOS. I'm going to do more tests but it seems that I've started to see this error since X.F 4.5

It happens for me with a CollectionView inside a tabbed page reproduceable on iOS

Steps to reproduce

  • Start reproduction project
  • Switch to 2nd tab
  • Switch back to first tab
  • Press button on first tab
  • Switch back on 2nd tab

Expected Behavior
The items added after a clear of the CollectionView gets displayed

Actual Behavior
CollectionView is not showing anything

Basic Information

  • Version with issue: 4.4.0 latest stable and 4.5.0.356 and 4.6.0.379-pre1
  • Last known good version: -
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:
  • iOS: 13
  • Android Support Library Version: -
  • Nuget Packages: -
  • Affected Devices: -

Reproduction Link
CollectionViewBindingRepro.zip

I cannot update to Xamarin Forms. 4.5 as as soon as I do it, the app for iOS doens't work anymore (it works fine on Android). When I go back to Xamarin Forms 4.4 then it works again on iOS.

I have a CollectionView on my first (after login) content page. on X.F. 4.5 and iOS, that contentview has a wrong layout: I can see the bottom half of the second item but it's like there is a white layout on top of the CollectionView so I can see nothing else.

Expected Behavior
The CollectionView shows items correctly

Actual Behavior
CollectionView is not showing items correctly

Basic Information

Version with issue: from 4.5.0.356
Last known good version: 4.4.0.991757
IDE: Visual Studio 2019
Platform Target Frameworks:
iOS: 13

I can add this, maybe it can help:
This issues seems to happen when the CollectonView is inside a RefreshView.
If I remove the RefreshView, then it works fine.

this bug happens for me also
i have a login page => after successful login a new app shell starts with tabs and the main tab contains a grid and that grid contains a refresh view inside this refresh view i have my collection view

Error Message
[CollectionView] An attempt to prepare a layout while a prepareLayout call was already in progress (i.e. reentrant call) has been ignored. Please file a bug. UICollectionView instance is (; layer = ; contentOffset: {0, -60}; contentSize: {375, 0}; adjustedContentInset: {0, 0, 0, 0}; layout: ; dataSource: >)

System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'

Expected Behavior
The CollectionView shows items correctly after loading of any refresh

Actual Behavior
app crash

Basic Information

Version with issue: 4.6.0.800 latest stable
Last known good version: -
IDE: Visual Studio 2019
Platform Target Frameworks:
iOS: 13.5

I have a problem the same with message above.

[CollectionView] An attempt to prepare a layout while a prepareLayout call was already in progress (i.e. reentrant call) has been ignored. Please file a bug. UICollectionView instance is (; layer = ; contentOffset: {0, 0}; contentSize: {272.5, 0}; adjustedContentInset: {0, 0, 0, 0}; layout: ; dataSource: >)

How to used:

 <DataTemplate x:Key="ItemViewTemplate">
                <Grid 
                    x:Name="ItemTemplate"
                    WidthRequest="120"
                    HeightRequest="100"
                    Style="{StaticResource StyleGrid}"
                    Padding="10" 
                    HorizontalOptions="FillAndExpand" 
                    VerticalOptions="FillAndExpand" 
                    BackgroundColor="White">
                    .....                 
                </Grid>
            </DataTemplate>
<CollectionView
                x:Name="itemCollectionView"  
                Grid.Column="2"
                VerticalScrollBarVisibility="Never"
                HorizontalScrollBarVisibility="Never"
                ItemsSource="{Binding SubCategoryOutputs}"
                ItemTemplate="{StaticResource ItemViewTemplate}">
                <CollectionView.ItemsLayout>
                    <GridItemsLayout       
                        Span="2"
                        Orientation="Vertical"
                        VerticalItemSpacing="0"
                        HorizontalItemSpacing="0" />
                </CollectionView.ItemsLayout>
            </CollectionView>

After load data completed it show message above and try to selected item to details it does't happen to show UI (stuck app) can't navigation back or do anything with application.

Basic Information
Version with issue: Latest stable 4.6.0.847
Last known good version: -
IDE: Visual Studio 2019
Platform Target Frameworks:
iOS: 13.5

So please help to resolve this problem ?

Thank you in advances.

I was able to recreate and fix this.
remove your collectionview from any nested scrollview guys.
it will work again as usual.

I was able to recreate and fix this.
remove your collectionview from any nested scrollview guys.
it will work again as usual.

I don't have scroll view on that page it's just nested grids and refresh view containing the collection view

I was able to recreate and fix this.
remove your collectionview from any nested scrollview guys.
it will work again as usual.

I don't have scroll view on that page it's just nested grids and refresh view containing the collection view

Hi,
Also noticed this.
is your collectionview is visible while you set the datasource?
if it or its container is not visible, just noticed this issue also occurs for me.

I was able to recreate and fix this.
remove your collectionview from any nested scrollview guys.
it will work again as usual.

I don't have scroll view on that page it's just nested grids and refresh view containing the collection view

Hi,
Also noticed this.
is your collectionview is visible while you set the datasource?
if it or its container is not visible, just noticed this issue also occurs for me.

The collection view and its containers are visible it just have empty template and search handler for shell page
Also i tried to remove the refresh view and search handler but it still crashing 馃槥

Also i tried to remove the refresh view and search handler but it still crashing 馃槥

for me, its not crashing. but freezing my friend.
can you add a try catch to InitializeComponents() method of your page and check?

I'm facing this issue as well on iOS:

[CollectionView] An attempt to prepare a layout while a prepareLayout call was already in progress (i.e. reentrant call) has been ignored. Please file a bug. UICollectionView instance is (; layer = ; contentOffset: {0, 0}; contentSize: {404, 0}; adjustedContentInset: {0, 0, 0, 0}; layout: ; dataSource: >)

I'm on a tabbed page. Is there any workaround?

Using the new feature "path" causes that proplem for me when i removed it from the collection view it loaded without crash

Information around the issue:

The issue occurred on a Tabbed Page, when loading around 300 items on the list. The collection view loads fine on the start, then while scrolling down the error appears. I was using Xamarin.Forms 4.7 SP1 latest version and I had to downgrade to 4.6.0.967.

I have the same problem :(
I had in xamarin 4.6.0.772 and now in 4.7.0.1142 latest release same problem

Xamarin.Mac
Version: 6.16.0.11 (Visual Studio Community)
Hash: aa73e4125
Branch: d16-5-xcode11.4
Build date: 2020-03-25 11:04:02-0400

Xamarin.iOS
Version: 13.18.2.1 (Visual Studio Community)
Hash: 29c4ea731
Branch: d16-6
Build date: 2020-05-26 17:03:05-0400

[CollectionView] An attempt to prepare a layout while a prepareLayout call was already in progress (i.e. reentrant call) has been ignored. Please file a bug. UICollectionView instance is (; layer = ; contentOffset: {0, 0}; contentSize: {1, 0}; adjustedContentInset: {0, 0, 0, 0}; layout: ; dataSource: >)
Captura de Pantalla 2020-07-20 a la(s) 21 43 02
Captura de Pantalla 2020-07-20 a la(s) 21 43 32

I am also now seeing this same issue after upgrading Xamarin.Forms from 4.5.0.356 to 4.8.0.1269. Did anyone by any chance find a workaround?

I had the same issue - and tried a lot of things... but eventually narrowed it down to this:
I have a CollectionView (in a RefreshView) bound to an itemssource with different datatypes. One of the items added had its own viewmodel, which loaded data from a REST api on a background thread - after data was received some properties were set affecting visibility of the item. this caused the error and the CollectionView wouldn't render anything.

I've changed my binding for ItemsSource to be set in codebehind after all (initial) items has been loaded from REST-backend. There are no longer any items, that load additional data, but is now rendered as simple items/models using a datatemplate selector.

Oddly enough, setting the binding through xaml, won't render the items - only setting binding after loading the first batch of items works on iOS. Android works as expected.

The underlying list of items is an ObservableCollection - but the issues are the same using a List.

I've also experienced similar problems, when using an ObservableCollection and calling property changed after adding to the items collection. This seems to trip on iOS also not rendering any items. Letting ObservableCollection handle the change notifications seemed to handle some of my issues.

Hope this helps.

I worked around this issue by initialazing the ObservableCollection in the constructor of the ViewModel with an empty item.

Was this page helpful?
0 / 5 - 0 ratings