[Mono-bugs] [Bug 430477] Debug.Assert() does not work in winform apps

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Sep 29 14:04:47 EDT 2008


User jpryor at novell.com added comment

Jonathan Pryor <jpryor at novell.com> changed:

           What    |Removed                                         |Added
                 CC|                                                |jpryor at novell.com

--- Comment #6 from Jonathan Pryor <jpryor at novell.com>  2008-09-29 12:04:46 MDT ---
It didn't work on .NET because the DefaultTraceListener was handling the
failure message first.  So to see your dialog you'd either have to clear all
the TraceListeners (as you did), or Ignore the first failure dialog, after
which you should see _your_ dialog.  (Yay, two dialogs for every failure

For Mono integration, I have two suggestions:

1. You should add this to mcs/class/Managed.Windows.Forms and find some
initialization method so that it's always present.  Do NOT call

2. More importantly, you should add code so that ShowDebugAssertMsg() grabs the
pre-exising DefaultTraceListener instance, and only shows the UI if
DefaultTraceListener.AssertUiEnabled is true, e.g. (untested):

private DialogResult ShowDebugAssertMsg(string message, string detailMessage)
    bool ignore = false;
    foreach (TraceListener tl in Debug.Listeners) {
        DefaultTraceListener d = tl as DefaultTraceListener;
        if (d != null && !d.AssertUiEnabled) {
            ignore = true;
    if (ignore)
        return DialogResult.Ignore;

    // as before...

The reason to do this is that DefaultTraceListener.AssertUiEnabled is
initialized based on the .exe.config file of the loaded app, thus allowing the
UI to be trivially enabled or disabled via the .config file.

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list