Skip to content

Commit 7164ea6

Browse files
authored
Fix stack trace for Trace.Fail and Debug.Fail (#15103)
1 parent 0fb4bf8 commit 7164ea6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/testhost.x86/TestHostTraceListener.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ private static DebugAssertException GetException(string? message)
4949
var debugMethodFound = false;
5050
var frameCount = 0;
5151
MethodBase? method = null;
52-
foreach (var f in stack.GetFrames())
52+
var frames = stack.GetFrames();
53+
foreach (var f in frames)
5354
{
5455
var m = f?.GetMethod();
5556
var declaringType = m?.DeclaringType;
@@ -65,7 +66,7 @@ private static DebugAssertException GetException(string? message)
6566
}
6667
}
6768

68-
var stackTrace = string.Join(Environment.NewLine, stack.ToString().Split(Environment.NewLine).TakeLast(frameCount));
69+
var stackTrace = new StackTrace(frames.TakeLast(frameCount)).ToString();
6970
var methodName = method != null ? $"{method.DeclaringType?.Name}.{method.Name}" : "<method>";
7071
var wholeMessage = $"Method {methodName} failed with '{message}', and was translated to {typeof(DebugAssertException).FullName} to avoid terminating the process hosting the test.";
7172

0 commit comments

Comments
 (0)