Question

I want to detect and report bugs in specific cases, using the same behavior as Debug.Assert(), but in a Release build. How can I do that?

Was it helpful?

Solution

You should be able to use Trace.Assert().

From MSDN:

Use the Trace.Assert method if you want to do assertions in release builds. The Debug.Assert method works only in debug builds.

OTHER TIPS

You can manually add the DEBUG constant while still having Release optimizations enabled.

In the Build tab of your project settings just check the box that enables the DEBUG constant.

enter image description here

This allows all functions that have [ConditionalAttribute("DEBUG")] (like Assert()) to still function in your compiled program.

EDIT: Grant's answer is even better, if possible use Trace.Assert instead. That function triggers on if the constant TRACE is defined and it is defined by default in Release builds. That will make sure you don't get any unforeseen side effects of enabling any other code that uses #if DEBUG or [ConditionalAttribute("DEBUG")] in your code.

Can't you turn on Tracing and perform tracing? You can use conditional tracing in Release mode. Also, you can implement some conditionally logging with log4net

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top