From 9c14efc0119ae583947107daba1193287bfabcb8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 11:38:03 -0700 Subject: [PATCH] Correct error messages for CoreCLR Win32 PAL uses in CoreLib (#76813) Contributes to #76736 Co-authored-by: Jan Kotas --- src/libraries/Common/src/System/IO/Win32Marshal.cs | 4 +++- .../src/System.Private.CoreLib.Shared.projitems | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) 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