Array index out of bounds error, - Solved

By Slayer_ ·
The trick is, its happening in a for each loop, so how is this possible?

Its a List(of t) type. Count shows 678 elements, however, if you try and access 677 it throws array index out of bounds. If you try to for each through it, on the last element it throws the same error.

What am I doing wrong?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -


by cmiller5400 In reply to Array index out of bounds ...

"For each" will only loop on the elements that are in the array, so I'd assume that it shouldn't generate an out of bounds error (well you know what they say about assuming )... Can you post some code?

Collapse -

Here is the code

by Slayer_ In reply to Array index out of bounds ...

Dim dc As DetectionCache
Dim dcToDelete As New ArrayList
For Each dc In aDestinationCache
If dc.Expired = True Then
End If
Catch ex As Exception
Throw ex
End Try

DetectionCache is a custom class that holds keys, values, and an expiry date/time
aDestinationCache is a List(of DetectionCache)

Collapse -

I think it had something to do with my serialized file

by Slayer_ In reply to Array index out of bounds ...

aDestinationCache is serialized and loaded and written to a file. When I emptied the file, it became happy.

Oddly, it was also erroring on query results from Linq queries when I for each'ed through the results.

Related Discussions

Related Forums