AutoFixture/AutoFixture

πŸ› System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' and object reference not set to an instance of an object

daniellondo opened this issue Β· 2 comments

Describe the Bug

  • System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'
  • System.NullReferenceException: 'Object reference not set to an instance of an object'

Scenario

I have 140 unit tests where I am using autoFixture, when I run them individually they work fine, but when I run all the tests I get these errors.
The evidence is in the attached files.

Expected Behavior

Tasks

  • Updated all AutoFixture and related libraries
  • Confirmed in support forums if behavior is expected

More Information

Screenshots

Screenshot_1
Screenshot_3

Thanks!

I cannot see how all this is wired up, but I read a lot of static here.

Maybe I am wrong, but from your screenshots I get the impression that all your tests call this InitializeData function. So when you run them in parallel the error is clear. The Fixture behaviors are not implemented in a thread safe manner.

Every test should get itΒ΄s own instance of the Fixture class.

Closing due to inactivity.