Skip to content

Commit

Permalink
Correct error messages for CoreCLR Win32 PAL uses in CoreLib
Browse files Browse the repository at this point in the history
Contributes to dotnet#76736
  • Loading branch information
jkotas committed Oct 7, 2022
1 parent e53a3d9 commit 2401d6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/libraries/Common/src/System/IO/Win32Marshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,12 @@
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WIN32_FIND_DATA.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.WIN32_FIND_DATA.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WriteFile_IntPtr.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.WriteFile_IntPtr.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_NativeOverlapped.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_NativeOverlapped.cs</Link>
</Compile>
Expand Down Expand Up @@ -1974,12 +1980,6 @@
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.SetEnvironmentVariable.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.SetEnvironmentVariable.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.WriteFile_IntPtr.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_IntPtr.cs</Link>
</Compile>
<Compile Include="$(CommonPath)System\IO\Win32Marshal.cs">
<Link>Common\System\IO\Win32Marshal.cs</Link>
</Compile>
Expand Down

0 comments on commit 2401d6c

Please sign in to comment.