Consider the following C# program:
using System;
using System.Diagnostics;
namespace Test
{
class MainClass
{
public static void Main (string[] args)
{
Debug.Assert(false);
Debug.Fail("fail!");
Console.WriteLine ("Hello World!");
}
}
}
When compiling this using:
dmcs -debug -d:DEBUG Main.cs
and then running it with:
mono --debug Main.exe
the assertion and fail seem to be ignored. The output is just:
Hello World!
I checked other related questions on StackOverflow, but I could not find a solution. In particular the solution give in Mono - Debug.Assert does not work does not work. (UPDATE: the updated solution does work, see below comments.)
I use Mono 2.10.5-1 on Ubuntu 11.10.
You can use the xml configuration, or you can place it under the control of your program by adding a trace listener at runtime:
This has the added advantage of you being able to enable it after the program has started.
C# on mono - http://ebsteblog.wordpress.com/2009/05/06/debugassert-and-mono/
Excerpt from the article:
...if you create a .config file for your app and set the assertuienabled attribute to true, you get the same dialog as with .NET... File app.config:
Old answer: C++ comment if you did not specify -define DEBUG on command line/compile options.
For debug add
at the beginning of the code or
for trace.
See the solution here: http://lists.ximian.com/pipermail/mono-list/2006-December/033774.html
p.s: I tried this with C++ not C#. This may not work for C#.