Reputation: 12672
Just for curiosity
I have this problem on my code.
e
is evaluated as false
, (and I know that is getting false by seeing the data in the db) but the if statement doesn't care that, and assumes that is true, and is trying to throwing the exception.
Any ideas why?
edit:
There is no ; at the end of line 16.
The value false
is correct, I have checked the database and is
correct that is getting false
, that was the expected
{}
works fine. BUT I WANT TO KNOW why in this way is not
working.x64
, I'm not able to do the changeUpvotes: 4
Views: 2036
Reputation: 28338
I saw a very similar question on SO recently but I cannot find it. While I'm off looking, here is what I remember from it, in case it helps ease your mind:
The symptoms were:
The reason has to do with the extra op codes that are emitted in Debug-enabled releases, to support step-through debugging. The actual IL code emitted for such releases includes extra "no-op" IL commands that do nothing except exist, and are used when stepping through code to break execution just before and/or after the "real" operations have run.
In this case, the IDE is just getting confused about which line of code is the "current" one based on the IL code it's trying to step through. The extra op code is there, as it should be, but the debugger IDE is incorrectly associating it with the previous line of code. The yellow highlight is in the wrong place.
I don't remember the exact conditions that make this happen (the answer to the original question actually dug into the IL to explain it, hopefully someone else can find that question!). Adding the braces causes the compiler to emit no-op op codes specifically to represent the braces, which is why the problem vanishes.
Upvotes: 5
Reputation: 1539
By chance - is there another variable somewhere defined named 'e' at a different scope, causing the compiler to get confused as to which value to use? Try changing 'e' to some other name.
Upvotes: 0