question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.InvalidOperationException: Cannot change ObservableCollection during a CollectionChanged event.

See original GitHub issue

We occasionally experience this error. Android, MvvmCross.

CardsView.AddChild (Xamarin.Forms.View topView, Xamarin.Forms.View[] views) System.InvalidOperationException: Cannot change ObservableCollection during a CollectionChanged event. ObservableCollection1[T].CheckReentrancy () ObservableCollection1[T].InsertItem (System.Int32 index, T item) Collection1[T].Insert (System.Int32 index, T item) ObservableWrapper2[TTrack,TRestrict].Insert (System.Int32 index, TRestrict item) CardsView.AddChild (Xamarin.Forms.View topView, Xamarin.Forms.View[] views) CardsView.GetViews (PanCardView.Enums.AnimationDirection animationDirection, PanCardView.Processors.ICardProcessor processor, System.Int32[] indeces) CardsView.SetupNextView () CardsView.SetupBackViews () CardsView+<SetCurrentView>d__202.MoveNext () ExceptionDispatchInfo.Throw ()

Unfortunately we do not have repro sample.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rkotulancommented, Aug 17, 2018

I have quite simple setup

View with CachedImage

 <panCardView:CarouselView
                ItemsSource="{Binding Items"
                SelectedIndex="{Binding CurrentIndex"
                HeightRequest="{Binding CarouselHeight">
                <panCardView:CarouselView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout BackgroundColor="White" Margin="0" Padding="0">
                            <forms:CachedImage Source="{Binding }" Margin="0" />
                        </StackLayout>
                    </DataTemplate>
                </panCardView:CarouselView.ItemTemplate>

                <controls1:IndicatorsControl SelectedIndicatorStyle="{StaticResource SelectedIndicatorItemStyle}" UnselectedIndicatorStyle="{StaticResource UnSelectedIndicatorItemStyle}" />
 </panCardView:CarouselView>

ViewModel

public override async Task Initialize()
{
            await base.Initialize();
            
            if (authenticationService.IsUserAuthenticated())
            {
                var userInfo = await authenticationService.GetAuthenticatedUser();
                IsVip = userInfo.IsVip;
            }

            if (IsVip)
            {
                TescoDoubleCardItems = new ObservableCollection<string>
                                           {
                                               "VIP_TMCZ_KUPON.png",
                                               "VIP_PECIVO.png",
                                               "VIP_OVOCE.png",
                                               "VIP_MLEKO.png",
                                               "VIP_MASO.png",
                                               "VIP_DROGERIE.png"
                                           };
            }
            else
            {
                TescoDoubleCardItems = new ObservableCollection<string> { "VIP_TMCZ_KUPON.png", };
            }
}

I will try to prepare repro sample later, but problem is that app crash occasionally.

0reactions
rkotulancommented, Aug 20, 2018

It seems to be ok. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Remove an item from an ObservableCollection in a ...
Calling .Remove() within the CollectionChanged event handler doesn't appear to be allowed. At runtime .NET throws an InvalidOperationException:.
Read more >
Exception: Cannot change ObservableCollection during a ...
I think the problem is that an ObservableCollection is not originally thread safe. The problem occurs for me when there are two different ......
Read more >
An observable collection cannot be modified during a change ...
General caveat: For both of the options described below, every change to the Data collection will result in a new event being raised,...
Read more >
Xamarin Forms Exception OnLoadMore - "Cannot change ...
When doing a "first load" of a datasource the DataGridView control invokes two times the LoadMore event. This causes the data to loaded...
Read more >
XamGrid - Cannot change ObservableCollection during a ...
I am using XamGrid which is bounded to collectionviewsource, apparently when i add filter row to the xamgrid (via below xaml) i get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found