did you ever see if(false) run the if block anyway?
I'm getting that at the moment.. bugging me for the past few hours. The condition in my IF is evaluating to false, but VS2010 Pro runs the if block anyway. Noone in my team can explain it; this is a new built laptop, windows 7, vs2010 pro and i've just converted the application to 64bit from its 32bit roots. I'm hestiant to even use this dev env any more if it's compiling code that runs when the IF is false, as it this will be used in banking systems..
Here's a short video, I have the cursor already positioned on the problematic if.. All I do is put the condition into the immediate window immediately before I step over. Condition reports FALSE in the immediate window, but when I choose step over from the debugger menu, it enters the IF regardless.. No prank; any trustworthy soul who uses TeamViewer remote desktop software is welcome to connect to my PC and see this happen for themselves, live.
Video attached.. It's a SWF video so it's in a zip file along with an HTML file that will act as a container.. just extract the two to your desktop and open the HTML, your browser will play the SWF.. Youre free to examine the HTML beforehand using notepad if you have any concerns about its potential content
Re: did you ever see if(false) run the if block anyway?
you know what's even weirder? I just F10'ed again while control was pointing to the "throw exception" line, and no exception was throown, the code just carried on as normal..
I see different things from the IDE here too:
Code:
string s;
if(false)
s= "s"; //ide shows error, unreachable code detected
if(false)
throw new Exception("whatever"); //no IDE warning of unreachable code.. what???
Re: did you ever see if(false) run the if block anyway?
Sorry, not downloading anything.
Please pose your real code- the pseudocode you posted isn't really going to help. There are a few possible ways I can think of that you're experiencing this, but I can't be certain without seeing real code.
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
Re: did you ever see if(false) run the if block anyway?
Well, the video shows the if statement being stepped into when the result is false. I tried applying the boolean NOT operator inside of the immediate window and I got an error "not available while Managed only debugging." != worked just fine. Total swing in the dark here, but perhaps the immediate window does strange things with the NOT operator? I know that soudns ridiculous, but have you tried storing the value of your call to Contains() in a variable first and checking what it returns?
Re: did you ever see if(false) run the if block anyway?
Maybe it's just some glitch in the graphical representation of the execution flow in the IDE, maybe the if-block doesn't actually get executed?
If you put a tracepoint there, does it output anything? (Or a breakpoint - does it get hit?)
Originally Posted by BigEd781
I tried applying the boolean NOT operator inside of the immediate window and I got an error "not available while Managed only debugging." != worked just fine. Total swing in the dark here, but perhaps the immediate window does strange things with the NOT operator?
Yup, "!something" wont work, but "?!something" will.
The ! symbol is used for SOS commands.
Re: did you ever see if(false) run the if block anyway?
Is it debg or release build? I think it could have something to do with compiler optimization (I bet for this reason) or a glitch in the .pdb file. Clean, rebuild and similar excercises don't help?
Re: did you ever see if(false) run the if block anyway?
Originally Posted by boudino
Is it debg or release build? I think it could have something to do with compiler optimization (I bet for this reason) or a glitch in the .pdb file. Clean, rebuild and similar excercises don't help?
I can't imagine that a compiler optimization would change the result of a call to Contains like that. Maybe the source doesn't match the executable?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.