{
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)
{
}
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);
}
}
{
public static partial class Debug
{
- private static string NewLine => "\r\n";
-
private static void ShowAssertDialog(string stackTrace, string message, string detailMessage)
{
if (Debugger.IsAttached)
}
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);
}
}
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
[System.Diagnostics.Conditional("DEBUG")]
public static void WriteLine(string message)
{
- Write(message + NewLine);
+ Write(message + Environment.NewLine);
}
[System.Diagnostics.Conditional("DEBUG")]
s_needIndent = false;
}
s_WriteCore(message);
- if (message.EndsWith(NewLine))
+ if (message.EndsWith(Environment.NewLine))
{
s_needIndent = true;
}
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)
{
}
}