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

See original GitHub issue

Hey Andrei, I try to implement the orientation change in my app and there is an error coming up. I’m not quite sure if its a CardView bug, but when you look at the call stack it seems to be an issue there or in XF. I use the latest version of both (2.0. 6 | 3.6.0.293080)

I have to different CardViews (Carousels) each in one page. When I change pages and then change my orientation to landscape an error occurs, I think it must be about the layout and the observable collections there, since I dont use any in this page where the error occurs. (There are no problems if I don’t change orientation)

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

ObservableCollection`1[T].CheckReentrancy ()
ObservableCollection`1[T].MoveItem (System.Int32 oldIndex, System.Int32 newIndex)
ObservableCollection`1[T].Move (System.Int32 oldIndex, System.Int32 newIndex)
Layout.LowerChild (Xamarin.Forms.View view) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:186
CardsView.SendChildrenToBackIfNeeded (Xamarin.Forms.View view, Xamarin.Forms.View topView)
CardsView.AddChild (Xamarin.Forms.View topView, Xamarin.Forms.View[] views)
CardsView.InitViews (PanCardView.Processors.ICardProcessor processor, PanCardView.Enums.AnimationDirection animationDirection, System.Collections.Generic.IEnumerable`1[T] bookedViews, System.Int32[] indeces)
CardsView.SetupPrevView (System.Int32 index)
CardsView.SetupBackViews (System.Nullable`1[T] index)
CardsView.SetCurrentView ()
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)
SyncContext+<>c__DisplayClass2_0.<Post>b__0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
shoeITcommented, Jun 5, 2019

Ok, may I know which nuget package version this fix was applied…?

the current one works fine, error is gone, thanks Andrei!

1reaction
shoeITcommented, Apr 12, 2019

thx I will se what I can do, its difficult to reproduce with a small sample

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