Original Post
I've been coding in C# for over 6 years. But I've never seen anything like the error I've just encountered. Inside an If statement, I attempt to iterate a collection using a foreach. When I run the program, I receive a stack overflow exception. However, the If statement is never actually run because its boolean condition is never true. When I highlight out the foreach line, the problem does not occur. I would guess that something is wrong with the foreach (not sure what), and that possibly due to CPU branch prediction the error occurs without the code even being directly hit. Has anyone else encountered this, that is encountered a piece of code that breaks their program even when it is not actually hit?