From 2be8e8da4ecaa4697dc9cdcc64b44bc54743a33e Mon Sep 17 00:00:00 2001 From: Phil Scott Date: Wed, 20 Nov 2024 10:37:30 -0500 Subject: [PATCH] Adds fallback for ExceptionFormatter in AOT --- .../Widgets/Exceptions/ExceptionFormatter.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs index 383e619..2291caf 100644 --- a/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs +++ b/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs @@ -27,6 +27,13 @@ internal static class ExceptionFormatter throw new ArgumentNullException(nameof(exception)); } + // fallback to default ToString() if someone in an AOT is insisting on using this method + var stackTrace = new StackTrace(exception, fNeedFileInfo: false); + if (stackTrace.GetFrame(0)?.GetMethod() is null) + { + return new Text(exception.ToString()); + } + return new Rows(GetMessage(exception, settings), GetStackFrames(exception, settings)).Expand(); }