diff --git a/src/System.Reflection.Metadata/src/System.Reflection.Metadata.csproj b/src/System.Reflection.Metadata/src/System.Reflection.Metadata.csproj index eb2b98e181a7..55b6dfe8f9b2 100644 --- a/src/System.Reflection.Metadata/src/System.Reflection.Metadata.csproj +++ b/src/System.Reflection.Metadata/src/System.Reflection.Metadata.csproj @@ -8,6 +8,12 @@ netcoreapp-Debug;netcoreapp-Release;netstandard-Debug;netstandard-Release;netstandard1.1-Debug;netstandard1.1-Release + + Common\Interop\Windows\Interop.Libraries.cs + + + Common\CoreLib\Interop\Windows\kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs + diff --git a/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.cs b/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.cs index dfa92e81d1aa..d0aefd47924a 100644 --- a/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.cs +++ b/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.cs @@ -53,12 +53,12 @@ internal static unsafe bool TryReadFile(Stream stream, byte* buffer, long start, return false; } - bool result = false; - int bytesRead = 0; + int result; + int bytesRead; try { - result = ReadFile(handle, buffer, size, out bytesRead, IntPtr.Zero); + result = Interop.Kernel32.ReadFile(handle, buffer, size, out bytesRead, IntPtr.Zero); } catch { @@ -66,7 +66,7 @@ internal static unsafe bool TryReadFile(Stream stream, byte* buffer, long start, return false; } - if (!result || bytesRead != size) + if (result == 0 || bytesRead != size) { // We used to throw here, but this is where we land if the FileStream was // opened with useAsync: true, which is currently the default on .NET Core. @@ -78,15 +78,5 @@ internal static unsafe bool TryReadFile(Stream stream, byte* buffer, long start, return true; } - - [DllImport(@"kernel32.dll", EntryPoint = "ReadFile", ExactSpelling = true, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool ReadFile( - SafeHandle fileHandle, - byte* buffer, - int byteCount, - out int bytesRead, - IntPtr overlapped - ); } } diff --git a/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.netstandard1.1.cs b/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.netstandard1.1.cs index 8b3aa67ee6a7..87b277a9cf83 100644 --- a/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.netstandard1.1.cs +++ b/src/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/FileStreamReadLightUp.netstandard1.1.cs @@ -100,12 +100,12 @@ internal static unsafe bool TryReadFile(Stream stream, byte* buffer, long start, return false; } - bool result = false; - int bytesRead = 0; + int result; + int bytesRead; try { - result = ReadFile(handle, buffer, size, out bytesRead, IntPtr.Zero); + result = Interop.Kernel32.ReadFile(handle, buffer, size, out bytesRead, IntPtr.Zero); } catch { @@ -113,7 +113,7 @@ internal static unsafe bool TryReadFile(Stream stream, byte* buffer, long start, return false; } - if (!result || bytesRead != size) + if (result == 0 || bytesRead != size) { // We used to throw here, but this is where we land if the FileStream was // opened with useAsync: true, which is currently the default on .NET Core. @@ -125,15 +125,5 @@ internal static unsafe bool TryReadFile(Stream stream, byte* buffer, long start, return true; } - - [DllImport(@"kernel32.dll", EntryPoint = "ReadFile", ExactSpelling = true, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool ReadFile( - SafeHandle fileHandle, - byte* buffer, - int byteCount, - out int bytesRead, - IntPtr overlapped - ); } } diff --git a/src/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj b/src/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj index a2454d6fe3e4..b6db7fb6fce8 100644 --- a/src/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj +++ b/src/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj @@ -2,6 +2,7 @@ true false + 436 netcoreapp-Debug;netcoreapp-Release;netfx-Debug;netfx-Release