diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.NativeAot.cs
index 32db59daefe2c2..f4c015efe34aa1 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.NativeAot.cs
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/StackTrace.NativeAot.cs
@@ -80,18 +80,19 @@ private void InitializeForIpAddressArray(IntPtr[] ipAddresses, int skipFrames, i
#if !TARGET_WASM
internal void ToString(TraceFormat traceFormat, StringBuilder builder)
{
- if (_stackFrames == null)
+ if (_stackFrames != null)
{
- return;
- }
-
- foreach (StackFrame frame in _stackFrames)
- {
- frame.AppendToStackTrace(builder);
+ foreach (StackFrame frame in _stackFrames)
+ {
+ frame?.AppendToStackTrace(builder);
+ }
}
if (traceFormat == TraceFormat.Normal && builder.Length >= Environment.NewLine.Length)
builder.Length -= Environment.NewLine.Length;
+
+ if (traceFormat == TraceFormat.TrailingNewLine && builder.Length == 0)
+ builder.AppendLine();
}
#endif
}
diff --git a/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/Internal/StackTraceMetadata/MethodNameFormatter.cs b/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/Internal/StackTraceMetadata/MethodNameFormatter.cs
index 5e84594fc62975..7ee32a0c420057 100644
--- a/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/Internal/StackTraceMetadata/MethodNameFormatter.cs
+++ b/src/coreclr/nativeaot/System.Private.StackTraceMetadata/src/Internal/StackTraceMetadata/MethodNameFormatter.cs
@@ -403,9 +403,10 @@ private void EmitPointerTypeName(PointerSignatureHandle pointerSigHandle)
///
/// Emit function pointer type.
///
- private void EmitFunctionPointerTypeName()
+ private static void EmitFunctionPointerTypeName()
{
- _outputBuilder.Append("IntPtr");
+ // Function pointer types have no textual representation and we have tests making sure
+ // they show up as empty strings in stack traces, so deliberately do nothing.
}
///
diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
index c76a1ee94d9759..0bc3f5f124210c 100644
--- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
+++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
@@ -172,6 +172,7 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()
public static bool IsAsyncFileIOSupported => !IsBrowser && !IsWasi;
public static bool IsLineNumbersSupported => !IsNativeAot;
+ public static bool IsILOffsetsSupported => !IsNativeAot;
public static bool IsInContainer => GetIsInContainer();
public static bool IsNotInContainer => !IsInContainer;
diff --git a/src/libraries/System.Diagnostics.StackTrace/tests/StackFrameExtensionsTests.cs b/src/libraries/System.Diagnostics.StackTrace/tests/StackFrameExtensionsTests.cs
index 3278cf3f5fd39d..931fe55adce172 100644
--- a/src/libraries/System.Diagnostics.StackTrace/tests/StackFrameExtensionsTests.cs
+++ b/src/libraries/System.Diagnostics.StackTrace/tests/StackFrameExtensionsTests.cs
@@ -16,21 +16,21 @@ public static IEnumerable