From 965835882c90125cc3ee8acd9b73bd3cf6a55031 Mon Sep 17 00:00:00 2001 From: Eduardo Velarde Date: Wed, 10 Jun 2026 12:02:38 -0700 Subject: [PATCH 1/2] Fix OOM message in Native AOT --- .../src/System/RuntimeExceptionHelpers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs index 52463e91b87e04..21956253591742 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs @@ -292,10 +292,10 @@ internal static unsafe void FailFast(string? message = null, Exception? exceptio } catch { - // If ToString() fails (for example, due to OOM), fall back to printing just the type name. + // If ToString() fails (for example, due to OOM), fall back to a simpler message. try { - Internal.Console.Error.Write(exception.GetType().FullName); + Internal.Console.Error.Write(exception is OutOfMemoryException ? "Out of memory." : exception.GetType().FullName); Internal.Console.Error.WriteLine(); } catch { } From 84b21f7c128c3e27fdccf694aff6079fc5f51e5f Mon Sep 17 00:00:00 2001 From: Eduardo Velarde Date: Tue, 16 Jun 2026 15:46:55 -0700 Subject: [PATCH 2/2] Use an allocation free comparison --- .../src/System/RuntimeExceptionHelpers.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs index 21956253591742..21ebbd00bed383 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs @@ -295,7 +295,8 @@ internal static unsafe void FailFast(string? message = null, Exception? exceptio // If ToString() fails (for example, due to OOM), fall back to a simpler message. try { - Internal.Console.Error.Write(exception is OutOfMemoryException ? "Out of memory." : exception.GetType().FullName); + // Use an allocation-free MethodTable comparison. + Internal.Console.Error.Write(exception.GetMethodTable() == Internal.Runtime.MethodTable.Of() ? "Out of memory." : exception.GetType().FullName); Internal.Console.Error.WriteLine(); } catch { }