.net - Why doesn't Debug.WriteLine work without the DEBUG constant? -


i ran issue had apparently disabled debug , trace constants on c# .net project working on, calls debug.writeline having no effect. (no debug output shown in output.) after re-enabling them as described here, started seeing output.

knowing how fix helpful, question why? far understand, debug compile time constant, , debug class compiled when build project. how calls debug.writeline skipped; shouldn't compiled other code?

i can think of few possible ways happen:

  • ms implemented special "feature" in compiler remove these calls without constant
  • visual studio sets debugger such or doesn't listen based on project setting debug output when runs
  • debug has crazy code examines calling assembly kind of flag set @ compile time

ms's documentation indicates expected behavior, haven't been able track down documentation how works. never occurred me, of course.

so how work?

have @ conditional attribute... causes method call ignored @ jit-time if specified symbol not defined. system.diagnostic.debug methods defined using attribute , value "debug" (see reference source example), hence calls don't occur if debug symbol not defined @ jit-time.