Warning: This is inherited legacy code that was initially put together in the early days of VB (not .net mind you). I have already dealt with all sorts of weirdness and evil bit this issue is weirder still.
I have a class that inherits from IEnumrable whose Count property is reporting 0 (zero) elements but the For Each loop steps into the loop body and tries to use the variable where it should just be moving on. My code:
On Error Resume Next
Dim d As Foo
For Each d In fooCollection
' use d and throws an exception
Next d
Weirder still, every time d is accessed i get an exception thrown in the output window:
A first chance exception of type
‘System.NullReferenceException’
but i’m not stopping on the exception (not in a try/catch block).
Is “On Error Resume Next” causing this weirdness?
Weirdness found:
Per Rowland’s and JohnH’s comments i checked the Foo class:
The GetEnumerator method inside of Foo didn’t actually return anything! It had an empty body. That coupled with the On Error Resume Next before the loop caused the havoc! Wow this was ugly. Thanks for the clues guys!
Get rid of the of the on error resume next. Can you post what Foo looks like ?