diff --git a/src/libraries/Common/src/System/IO/Win32Marshal.cs b/src/libraries/Common/src/System/IO/Win32Marshal.cs index ef2793dcb329f..ad2c81e9fc515 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 211c20005ebbd..cf96f22bb05d5 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 @@ -1795,6 +1795,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 @@ -1974,12 +1980,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