This project is read-only.


Collection was modified; enumeration operation may not execute.


Foq 1.4, rarely Mock.Verify() raises the following exception:
System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at[T](FSharpFunc`2 f, IEnumerator`1 e, FSharpRef`1 started, Unit unitVar0)
at Microsoft.FSharp.Collections.IEnumerator.filter@180.System-Collections-IEnumerator-MoveNext()
at Microsoft.FSharp.Collections.SeqModule.Length[T](IEnumerable`1 source)
at Foq.Mock.Verify(FSharpExpr expr, Times expectedTimes)
Closed Jan 26, 2014 at 7:34 PM by ptrelford


ptrelford wrote Jan 23, 2014 at 7:58 AM

The exception appears to indicate that the collection of recorded member invocations on the mock object was modified while iterating over it to verify the number of calls made.

This could happen if you're code is calling members on the mock object on another thread.

The verification API of Foq is unfortunately not currently thread safe, which is an oversight on my side, I will try to address this in the next version by switching from a mutable .Net List to an F# list so that I can simply take a reference to the current list when verify is invoked..

ptrelford wrote Jan 26, 2014 at 3:59 PM

Now fixed in source, will be part of Foq 1.5 release.