[Mono-list] Debug.Assert(): usable in current form?

Paul Melis p.e.c.melis at rug.nl
Fri Dec 29 07:03:40 EST 2006


Hi there,

After two hours of bug hunting in my ray-tracer code with mono 1.2.2 I
found that System.Diagnostics.Debug.Assert() isn't called without
compiling sources with #define DEBUG (or corresponding (g)mcs flag).

Fine.

After setting the flag and still not getting any output in a case I was
sure there should be some -- Debug.Assert(false) -- I managed to find in
a bug report that mentioned there is no output at all by default!

This is not mentioned in the FAQ, on the wiki or in the documentation.

After adding a ConsoleTraceListener to fix this I finally get output for
the failed assertions but there are no line number in the output...

SIGH

Is there a way to get failing asserts to print their line numbers to the
console?? And yes, I am compiling and running with -debug/--debug

Here's a small example program

// t.cs
#define DEBUG
#define TRACE

using System;
using System.Diagnostics;

class Test
{
     public static void Main()
     {
         Debug.Listeners.Add(new ConsoleTraceListener());

         Debug.Assert(false);
     }
};

When compiled with

gmcs -out:t.exe -debug t.cs

and run with

mono --debug t.exe

I get

---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----

    at System.Diagnostics.TraceImpl.Assert ()
    at System.Diagnostics.Debug.Assert ()
    at Test.Main ()
---- Assert Long Message ----

I.e. no line numbers. Without those my assert statements are useless as
there are several within the same method.

Paul


More information about the Mono-list mailing list