Thursday 10 August 2017

Debug in release mode

Imagine there is a scenario where you need to check the values of different variables at runtime - your usual response will be to run the application in debug mode and put a breakpoint at appropriate place. However, there are situations where code needs to be run in "release" mode because your code has compilation directives e.g. #if DEBUG. In such cases it becomes difficult to run the application and expect to know the values without some sort of trace/log statements.

There is a way to achieve this through Visual Studio as well. 


You can uncheck the option to "Optimize Code" and run the code in release mode. You will be able to hit the breakpoint and check values.


Caution: Do not make these changes for non-localbox environments as there is performance penalty and you lose the goodness of compiler optimization that help boost performance of application in release mode.