Came across an issue when writing some code to load my app's settings-- the following code produces an InvalidOperationException error:
For Each c As MapInfo In CurrentMaps AddMap(c, False) Next The debugger highlights the Next part, and from the MSDN page on the error, it looks like this is because the collection (CurrentMaps) has somehow changed from when it last bumped the enumerator (to process the For Each).
Not sure why that would happen, though, as AddMap takes the MapInfo ByVal and doesn't touch the input (so the collection is not changed).
I changed it to this, which works perfectly fine:
For i As Integer = 0 To CurrentMaps.Count - 1 AddMap(CurrentMaps(i), False) Next Those should functionally work the same, right? Any idea why the For Each one doesn't work?
Edit:
Ah figured it out-- the problem is that I use CurrentMaps as a temporary variable (collection keeping track of current maps), and AddMap is usually used within the app to add a new map (which means both updating UI and adding it to CurrentMaps).
Here (when loading app), I'm just using AddMap to update the UI, but the sub call to add the item to CurrentMaps was still there, so it was indeed modifying CurrentMaps.
Thanks for the input, all!
AddMapdo? Does it ever touchCurrentMaps?