namespace System.Diagnostics { internal static class MyDebug { [Conditional("DEBUG"), DebuggerNonUserCode()] public static void Assert(bool condition) { MyDebug.Assert(condition, string.Empty); } [Conditional("DEBUG"), DebuggerNonUserCode()] public static void Assert(bool condition, string message) { // no op if condition is true if (condition) return; // else if false create assert message for device display and Output window string assMsg = "---- DEBUG ASSERTION FAILED ----" + Environment.NewLine + message + Environment.NewLine #if !NETFX_CORE // can't get stack trace in WinRT + new StackTrace().ToString() #endif ; // ...then output the assert message... Debug.WriteLine(assMsg); // ...and display the message // ...and break in the debugger #if NETFX_CORE Contracts.Contract.Assert(condition, message); #else try { System.Windows.MessageBox.Show(assMsg); } catch (InvalidOperationException) { /* e.g. called from launch code on WP8 */} Debugger.Break(); #endif } } }