I've got this really, really weird error that I've never been able to pin down (it happens very rarely). Basically, I have a C# application that was randomly throwing an unknown exception on exit. I've managed to catch it in the debugger this time, and it turns out that calling `Application.Exit()` is throwing a `System.InvalidOperationException` with the following message:

> 
> A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
> 
> 
> Additional information: Collection was modified; enumeration operation may not execute.
> 
> 
> 

I'm not sure *what* this collection that has been allegedly modified is, or who it was that modified it.

The stack trace isn't very helpful:

> 
> mscorlib.dll!System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
>  + 0x13f bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ExitInternal()
>  + 0x112 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.Exit(System.ComponentModel.CancelEventArgs
>  e) + 0x65 bytes
> 
> 
> 

Any idea how I can find out which ArrayList it is that has been modified? I don't think it's anything I'm doing explicitly, more likely an action I'm doing that's modifying the underlying state of the .NET framework during the middle of an operation that MS wasn't expecting..