Closed arthurrump closed 7 years ago
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at System.Linq.Enumerable.<ExceptIterator>d__1`1.MoveNext()
at Zermelo.App.UWP.Helpers.ObservableCollectionExtensions.MorphInto[TSource](ObservableCollection`1 first, IEnumerable`1 second)
From the HockeyApp report:
Exception Type: System.InvalidOperationException
Crashed Thread: 3
Application Specific Information:
Collection was modified; enumeration operation may not execute.
Exception Stack:
System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
System.Collections.Generic.List`1.Enumerator.MoveNextRare()
System.Collections.Generic.List`1.Enumerator.MoveNext()
System.Linq.Enumerable.<ExceptIterator>d__1`1.MoveNext()
Zermelo.App.UWP.Helpers.ObservableCollectionExtensions.MorphInto[TSource](ObservableCollection`1 first, IEnumerable`1 second)
Zermelo.App.UWP.ViewModels.AnnouncementsViewModel.<GetAnnouncements>b__3_0(IEnumerable`1 a)
System.Reactive.AnonymousSafeObserver`1.OnNext(T value)
System.Reactive.ScheduledObserver`1.Run(Object state, Action`1 recurse)
System.Reactive.Concurrency.Scheduler.<>c__DisplayClass50`1.<InvokeRec1>b__4d(TState state1)
System.Reactive.Concurrency.Scheduler.InvokeRec1[TState](IScheduler scheduler, Pair`2 pair)
System.Reactive.Concurrency.CoreDispatcherScheduler.<>c__DisplayClass2`1.<Schedule>b__0()
System.Reactive.Concurrency.CoreDispatcherScheduler.<>c__DisplayClass2`1.<>c__DisplayClass4.<Schedule>b__1(Object o, Object e)
Windows.ApplicationModel.Core.UnhandledError.Propagate()
Microsoft.HockeyApp.Extensibility.Windows.UnhandledExceptionTelemetryModule.CoreApplication_UnhandledErrorDetected(Object sender, UnhandledErrorDetectedEventArgs e)
Nope, afc2f4a didn't fix this 😒
Exception gets thrown in the Remove loop in ObservableCollectionExtensions.MorphInto(), on opening the the Announcements view for the first time on a day.
When iterating over remove
in the foreach, the iterator calls MoveNextRare() when executing MoveNext(), because the version
of the list has changed while iterating, which means that the remove
list changed while iterating over it.
I'll add a DebugList
type to figure out what's going on inside.
Relevant StackOverflow question: before digging in deeper into the list, I'll try the suggestion in the answer.
The app doesn't crash anymore (yay!), but the ordering of the items somehow still gets messed up: Refresh doesn't reorder the items, restart does.
It looks to be fixed now.
It doesn't happen very consistedly, though. I can't reproduce it at the moment, so I'll come back to this later.