An exception

Can you help me knowing the reason of this exception because I’m not able to debug it as it doesn’t happen in my classes.
OnPaint: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveN ext()
at Northwoods.Go.GoLayer.Paint(Graphics g, GoView view, RectangleF clipRect)
at Northwoods.Go.GoView.PaintObjects(Boolean doc, Boolean view, Graphics g, RectangleF clipRect)
at Northwoods.Go.GoView.PaintView(Graphics g, RectangleF clipRect)
at Northwoods.Go.GoView.onPaintCanvas(PaintEventArgs evt)
at Northwoods.Go.GoView.OnPaint(PaintEventArgs evt)
A first chance exception of type ‘System.InvalidOperationException’ occurred in Northwoods.Go.dll
Thanks

Do you have code running in a separate thread that is modifying the document, perhaps by adding or removing some objects from a layer?
If so, you should synchronize on the GoView, since the Controls of your Form are painting and handling events on their own thread.

Hi Actually my code is running on a separate thread. But when I eliminate threading, exception still raise. I lately switched from Framework 1.1 to Framework 2.0 do you think this can be the cause of this exception as the same code was running on older version. Appreciating your help Thanks

Have you overridden any GoObject.Paint methods? Do they modify any data structures during painting? If so, that’s another no-no. I don’t think there is any explicit prohibition, as there is for calling Control methods from a different thread. But it’s bad programming practice to modify anything while painting.
Are you sure you have removed all instances of mutating code on other threads? I don’t see how else to get that exception.
A fair percentage of our customers seem to have switched to .NET 2.0 for development. But we haven’t heard of any problems like this.