Is it true! = True, or is AccessViolationException strange?
source link: https://www.codesd.com/item/is-it-true-true-or-is-accessviolationexception-strange.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Is it true! = True, or is AccessViolationException strange?
Whilst writing code I ran into a strange situation where my if
returns true, even if the test is clearly false. I have dumbed down the code to see if I am missing something, but the throw AccessViolationException()
keeps executing.
bool valid = true;
if (valid != true)
{
throw new AccessViolationException("WTF");
}
Does AccessViolationException
have strange powers, or has my computer gone off the deep end?
Edit: The "dumbed down" means I took out all extra functions and this is the code that I was left with. These few lines are a copy and paste of what is in my application. This is my real code
Edit 2: I cleaned the solution, rebuild, rebooted.
The code currently looks like this and I am still getting the same problem where the if
returns true.
bool valid = true;
if (valid != true)
{
throw new Exception("WTF");
}
Similar code in another function works as expected. The above code is EXACTLY what is in my function at the moment.
I am pretty sure, that your code is not that, what is running on your computer. For some strange reason the compiler does not compile your code (well), and some of your previous version runs. Rebuilding (as mentioned in one comment) is a good try, but not sure it succeeds. Instead:
- exit Visual Studio
- Delete "bin" and "obj" folders in your project directory
- Open VS and your project, again
- Comile, run, and be happy.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK