diff --git a/src/libraries/Common/src/System/IO/Win32Marshal.cs b/src/libraries/Common/src/System/IO/Win32Marshal.cs
index cbc75603c428b..15e84ed97f5cb 100644
--- a/src/libraries/Common/src/System/IO/Win32Marshal.cs
+++ b/src/libraries/Common/src/System/IO/Win32Marshal.cs
@@ -68,7 +68,9 @@ internal static Exception GetExceptionForWin32Error(int errorCode, string? path
static string GetPInvokeErrorMessage(int errorCode)
{
-#if NET7_0_OR_GREATER
+ // Call Kernel32.GetMessage directly in CoreLib. It eliminates one level of indirection and it is necessary to
+ // produce correct error messages for CoreCLR Win32 PAL.
+#if NET7_0_OR_GREATER && !SYSTEM_PRIVATE_CORELIB
return Marshal.GetPInvokeErrorMessage(errorCode);
#else
return Interop.Kernel32.GetMessage(errorCode);
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 41da05793059e..344fdcc2af669 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -1790,6 +1790,12 @@
Common\Interop\Windows\Kernel32\Interop.WIN32_FIND_DATA.cs
+
+ Common\Interop\Windows\Kernel32\Interop.WriteFile_IntPtr.cs
+
+
+ Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs
+
Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_NativeOverlapped.cs
@@ -1969,12 +1975,6 @@
Common\Interop\Windows\Kernel32\Interop.SetEnvironmentVariable.cs
-
- Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs
-
-
- Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs
-
Common\System\IO\Win32Marshal.cs