[Mono-list] System.Diagnostics.Debug.Assert()

Jonathan Pryor jonpryor at vt.edu
Fri Oct 28 14:16:25 EDT 2011

On Oct 27, 2011, at 1:33 PM, Steve Lessard wrote:
> Debug builds of my Mono command line application blow right by all Debug.Assert statements, even the ones I know fail the assertion. Heck, even Debug.Assert(false, "Foo") gets ignored.  Neither running standalone on the command line via Terminal.app nor running in MonoDevelop's debugger makes a difference; the asserts are always ignored.  I've checked, double-checked, and even triple checked that I am created Debug builds. Is there any way to force Mono to honor the asserts?

By default, the DefaultTraceListener prints nothing (as there's no real equivalent to OutputDebugString() on not-Windows). You can set an environment variable to override this behavior; see the remarks for the DefaultTraceListener type:


	$ export MONO_TRACE_LISTENER=Console.Error:+++
	$ mono yourapp.exe

However, this is purely console based, so no dialog box yelling "abort, retry, ignore." If you want something more elaborate, you'll need to write it and add it to the Listeners collection, as Nicholas Frechette suggested.

You should also re-read the compiler output to ensure that -define:DEBUG is on the command line, or add a `#define DEBUG` to the relevant file, otherwise the compiler will omit the Debug.Assert() call.

 - Jon

More information about the Mono-list mailing list