static void AddStackTrace(StringBuilder sb, Exception ex) { if (ex is ReflectionTypeLoadException rtle) { AddReflectionTypeLoadExceptionDetails(rtle, sb); } sb.AppendLine(ex.GetType().FullName); try { sb.AppendLine(StackTraceHelper.GetCleanStackTrace(ex)); } catch // Sometimes fails printing the trace { sb.AppendLine(ex.StackTrace); } }