2

I have a Xamarin forms project which consists of a ColectionView whose ItemSource is backed by a bindable property of type ObservableCollection in the ViewModel. Adding new items to the ObservableCollection is throwing NSInternalInconsistencyException, that too only on actual device whereas in the simulator it's working fine. Also if I create a new local parameter to hold the ItemSources values until all items are added to it and assigning this to the ItemSource bound property also works.

ObservableCollection<ExploreUIDataSet> _exploreDataList = new ObservableCollection<ExploreUIDataSet>();
        public ObservableCollection<ExploreUIDataSet> ExploreDataList
        {
            get { return _exploreDataList; }
            set { _exploreDataList = value; OnPropertyChanged(nameof(ExploreDataList)); }
        }

ExploreDataList.Add() will trow NSInternalInconsistencyException. Creating a local variable and adding all values to it and assigning it back to ExploreDataList is working fine. In native ios projects, we used to handle such changes in source through batch updates. But in forms do we need to do that, especially when the CollectionView is backed by the observable collection. Also having a Stacklayout with BindabLayout.itemsource as the ExploreDataList works even when we add new items into the ObservableCollection.

ie the below code works

<StackLayout Spacing="{DynamicResource Spacing10}"
                                     Padding="{DynamicResource ExploreMainStkPadding}"
                                     BindableLayout.ItemsSource="{Binding ExploreDataList}"
                                     BindableLayout.ItemTemplateSelector="{DynamicResource ExploreSelector}">
                        </StackLayout>

whereas the below CollectionView code fails

<CollectionView VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" ItemsSource="{Binding ExploreDataList}" ItemTemplate="{DynamicResource ExploreSelector}"/>
Midhun Kumar
  • 549
  • 5
  • 23
  • @Midhum,I create simple collectionview sample, and adding some data in Observablecollection, I don't find any issue, so can you post one simple sample that can reproduce your issue here? I will help you to test it. – Cherry Bu - MSFT Nov 25 '19 at 08:19
  • Hi @CherryBu-MSFT on further investigation it was observed that it works fine in iPhone 7 plus. (13.2.3), iPad Air 2 (13.1.2) and the exception is thrown in Phone 6 plus (12.4). Also the same in android 10 is throwing Cannot access a disposed object. – Midhun Kumar Nov 25 '19 at 12:08
  • I suggest you can try to other android 8.0,6.0 or other device to test, because I use android 8.1, having no issue, so if possible, you can provide one simple sample at github, I will try to help you to test. – Cherry Bu - MSFT Nov 26 '19 at 07:52

0 Answers0