0

In my .NET MVC 4 site I use #If DEBUG Then in a few places. Lately I've noticed that there seems to be some issues with the DEBUG variable. This issue keeps happening

Here is some code I put in a controller action to test my problem:

If DEBUG Then
    ViewData("test") = True
#Else
    ViewData("test") = False
#End If

If I run my site multiple times alternating between debug and release modes, at first the code will work but after a few tries, the code block above will get stuck into thinking it's in release mode or get get stuck into thinking it's in debug mode. At this point it doesn't matter if I'm in debug or release mode, the stupid thing will cling to whatever value it got stuck on and go to the code block for that value.

In release mode the = True line is greyed out. In debug mode the = False line is greyed out. So that works. But the code might still run a greyed out line if that code corresponds to the value the code is stuck on.

Things that don't fix it: -alternating some more -restarting VS -restarting computer -unloading project

The only thing that seems to fix it is changing the conditional statements or adding more #If DEBUG Then code somewhere else. It's as if the compiler doesn't reread the conditionals until something changes. This only happens on one VS project I'm working on and doesn't happen for other projects.

greenonion
  • 105
  • 1
  • 7
  • Did you check this? http://stackoverflow.com/questions/6912273/if-debug-is-ignored-vb-net-or-c – Esselans Nov 20 '13 at 20:14
  • yep. Also my problem is different. Sometimes DEBUG is defined and other times it's not. Depends on which way the code decides to get stuck. It seems like a random glitch rather than a setting. – greenonion Nov 20 '13 at 21:51

1 Answers1

1

This may be something that you left out of your paste but in the first IF you are missing # it should be #If Debug instead If Debug.

user2117229
  • 135
  • 3
  • 8