2
Answers

IndexOutOfRange Exception on foreach loop

Bill

Bill

16y
5.3k
1
I am getting a wierd result in my code sporadically.  First of all, I am using an old VB .NET client dll which uses a Microsoft.VisualBasic.Collection, ugh! When I loop through the collection in my C# code, I occasionally get an exception.

the code ..
foreach (Tag tag in object.Tags)
{
   ...
}
sometimes I get an IndexOutOfRange, sometimes a NullReference, the code is invoked by a thread timer.  Is it that the Collection isn't thread safe?  It runs fine on my XP development machine, but not on the Windows Server 2003R2 server.  I dont get it.

Any ideas?
Answers (2)