Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug.Assert(false) does not trigger in win8 Metro apps

I notice Debug.Assert does not trigger in Metro apps, however, if the project is a traditional one like Console or WinForm, it does trigger. And yes, I am in Debug mode.

Is it a setting not properly set in Visual Studio (11 Beta)? Or Debug.Assert is intended to be disabled in metro apps?

I know many exceptions are swallowed during the execution of Metro apps, but Debug.Assert is so handy that I can't think of a reason why it should be disabled.

like image 207
kennyzx Avatar asked May 10 '12 05:05

kennyzx


2 Answers

Seems like a bug. I would roll out my own assert method. Something like:

[Conditional("DEBUG")]
public static void Assert(bool condition)
{
    if (!condition)
        System.Diagnostics.Debugger.Break();
}
like image 70
Filip Skakun Avatar answered Oct 31 '22 03:10

Filip Skakun


It does trigger, look in the Output window. It just doesn't automatically prompt you to ask if you want a debugger break and thus just keeps motoring.

The DefaultTraceListener.AssertUIEnabled property is false. That's an implementation problem, can't display a message box on top of Metro UI. Which does actually work but the monitor switches to the desktop, pretty undesirable when you would have liked to click No. Hard to solve and no doubt on the todo list. You can't easily get to the property to set it to true, it is inaccessible from the metadata. Filip's workaround sounds half-decent.

like image 39
Hans Passant Avatar answered Oct 31 '22 04:10

Hans Passant