Debug.Assert FF (#10652)
authorDan Moseley <danmose@microsoft.com>
Tue, 4 Apr 2017 00:15:24 +0000 (17:15 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Apr 2017 00:15:24 +0000 (17:15 -0700)
src/mscorlib/src/System/Diagnostics/Debug.Unix.cs
src/mscorlib/src/System/Diagnostics/Debug.Windows.cs
src/mscorlib/src/System/Diagnostics/Debug.cs

index 2ec76a5d18ee9cf035d7be3339c83639b5953118..495f2f713c1830799c0750c28421c023c7141520 100644 (file)
@@ -8,11 +8,7 @@ namespace System.Diagnostics
 {
     public static partial class Debug
     {
-        private static string NewLine => "\n"; 
-
-        private const string EnvVar_DebugWriteToStdErr = "COMPlus_DebugWriteToStdErr";
-        private static readonly bool s_shouldWriteToStdErr = 
-            Internal.Runtime.Augments.EnvironmentAugments.GetEnvironmentVariable(EnvVar_DebugWriteToStdErr) == "1";
+        private static readonly bool s_shouldWriteToStdErr = Environment.GetEnvironmentVariable("COMPlus_DebugWriteToStdErr") == "1";
 
         private static void ShowAssertDialog(string stackTrace, string message, string detailMessage)
         {
@@ -22,16 +18,11 @@ namespace System.Diagnostics
             }
             else
             {
-                // TODO: #3708 Determine if/how to put up a dialog instead.
-                var exc = new DebugAssertException(message, detailMessage, stackTrace);
-                if (!s_shouldWriteToStdErr) 
-                {
-                    // We always want to print out Debug.Assert failures to stderr, even if
-                    // !s_shouldWriteToStdErr, so if it wouldn't have been printed in
-                    // WriteCore (only when s_shouldWriteToStdErr), print it here.
-                    WriteToStderr(exc.Message);
-                }
-                throw exc;
+                // In Core, we do not show a dialog.
+                // Fail in order to avoid anyone catching an exception and masking
+                // an assert failure.
+                var ex = new DebugAssertException(message, detailMessage, stackTrace);
+                Environment.FailFast(ex.Message, ex);
             }
         }
 
index f9b097c2309ff1014765db17ca47b20a896a046c..095e9b698574e88e896275a4588f64241ddca022 100644 (file)
@@ -6,8 +6,6 @@ namespace System.Diagnostics
 {
     public static partial class Debug
     {
-        private static string NewLine => "\r\n";
-
         private static void ShowAssertDialog(string stackTrace, string message, string detailMessage)
         {
             if (Debugger.IsAttached)
@@ -16,8 +14,11 @@ namespace System.Diagnostics
             }
             else
             {
-                // TODO: #3708 Determine if/how to put up a dialog instead.
-                throw new DebugAssertException(message, detailMessage, stackTrace);
+                // In Core, we do not show a dialog.
+                // Fail in order to avoid anyone catching an exception and masking
+                // an assert failure.
+                var ex = new DebugAssertException(message, detailMessage, stackTrace);
+                Environment.FailFast(ex.Message, ex);
             }
         }
 
index 2dfde8d90390adda2f96ee3a1feb00d560d02260..59f3c378da211c1f6280d087825353f083c4a566 100644 (file)
@@ -122,7 +122,7 @@ namespace System.Diagnostics
 
         private static string FormatAssert(string stackTrace, string message, string detailMessage)
         {
-            string newLine = GetIndentString() + NewLine;
+            string newLine = GetIndentString() + Environment.NewLine;
             return SR.DebugAssertBanner + newLine
                    + SR.DebugAssertShortMessage + newLine
                    + message + newLine
@@ -140,7 +140,7 @@ namespace System.Diagnostics
         [System.Diagnostics.Conditional("DEBUG")]
         public static void WriteLine(string message)
         {
-            Write(message + NewLine);
+            Write(message + Environment.NewLine);
         }
 
         [System.Diagnostics.Conditional("DEBUG")]
@@ -159,7 +159,7 @@ namespace System.Diagnostics
                     s_needIndent = false;
                 }
                 s_WriteCore(message);
-                if (message.EndsWith(NewLine))
+                if (message.EndsWith(Environment.NewLine))
                 {
                     s_needIndent = true;
                 }
@@ -311,7 +311,7 @@ namespace System.Diagnostics
         private sealed class DebugAssertException : Exception
         {
             internal DebugAssertException(string message, string detailMessage, string stackTrace) :
-                base(message + NewLine + detailMessage + NewLine + stackTrace)
+                base(message + Environment.NewLine + detailMessage + Environment.NewLine + stackTrace)
             {
             }
         }