-3

Did anyone see this error? I'm not able to understand what code statement did it, as it isn't available in the stacktrace.

System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.Reactive.PlatformServices.DefaultExceptionServices.Rethrow(Exception exception) at System.Reactive.AnonymousSafeObserver1.OnError(Exception error) at System.Reactive.Concurrency.ObserveOn1.?.OnErrorPosted(Object error) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

Application is wpf C#.net using Reactive. There are multiple locations where Reactive is being used, and the collections are locked for read/write operations using lock as a synchronization mechanism.

Note: In the entire code, I'm not iterating through the subscriber list or modifying it as well.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Angela F
  • 79
  • 1
  • 1
  • 10
  • 1
    Sounds like a for-each loop is trying to modify the collection it's looping over. – LarsTech Aug 07 '18 at 14:53
  • We definitely need some more details, but judging from the message it would seem like your modifying an element of a collection you're currently iterating on (with foreach for example) See: https://stackoverflow.com/questions/604831/collection-was-modified-enumeration-operation-may-not-execute – GigiSan Aug 07 '18 at 14:54

1 Answers1

0

You have a foreach that invokes some changes on the enumerated collection. That is disallowed.

Alternatively another thread is changing the enumerated collection concurrently, which will also result in an exception.

V0ldek
  • 9,623
  • 1
  • 26
  • 57