Debug.Assert and Mono

On Microsoft’s .NET implementation on Windows a Debug.Fail() (which is equal to a Debug.Assert(false)) when run on a debug build displays a dialog box with the options Abort, Retry, Ignore. When run in the debugger it also displays the call stack.

On Mono however no dialog box shows; it behaves the same as when the user pressed ‘Ignore’. What’s worse is that it doesn’t display the call stack by default, even when run in debugger. This doesn’t give any hint if an exception happened.

But: some research showed that there is an environment variable MONO_TRACE_LISTENER that can be set that outputs the call stack to wherever:

export MONO_TRACE_LISTENER=Console.Out

In MonoDevelop you can set the environment variable in Project/Options/Run/General.

Some background information can be found in the Mono bug #317040.

And even better: if you create a .config file for your app and set the assertuienabled attribute to true, you get the same dialog as with .NET (discussion in bug #430477):

File app.config:
<?xml version="1.0" encoding="UTF-8"?>
        <assert assertuienabled="true" />

But there are still some differences to .NET: if the message box displays we don’t get a call stack in the output. I guess it might be possible to add another TraceListener (e.g. ConsoleTraceListener) that takes care of that.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s