From f8a86435b0200fb7efb2649b4b622596a9a8e43c Mon Sep 17 00:00:00 2001 From: Kareem Zedan Date: Tue, 27 Apr 2021 20:03:42 +0100 Subject: [PATCH 1/6] remove Marshal.GetLastWin32Error --- .../src/Interop/Windows/Kernel32/Interop.FormatMessage.cs | 2 +- src/libraries/Common/src/System/IO/Win32Marshal.cs | 2 +- .../src/Internal/IO/File.Windows.cs | 4 ++-- .../src/System/Environment.Variables.Windows.cs | 4 ++-- .../src/System/Environment.Win32.cs | 6 +++--- .../src/System/Environment.Windows.cs | 2 +- .../src/System/Globalization/CompareInfo.Nls.cs | 6 +++--- .../src/System/Globalization/IdnMapping.Nls.cs | 2 +- .../src/System/Globalization/Normalization.Nls.cs | 4 ++-- .../src/System/IO/PathHelper.Windows.cs | 4 ++-- .../src/System/IO/Strategies/FileStreamHelpers.Windows.cs | 8 ++++---- ...t5CompatFileStreamStrategy.CompletionSource.Windows.cs | 2 +- .../src/System/Runtime/InteropServices/Marshal.cs | 7 +------ .../src/System/Security/SecureString.Windows.cs | 4 ++-- .../src/System/Threading/EventWaitHandle.Windows.cs | 4 ++-- .../src/System/Threading/LowLevelLifoSemaphore.Windows.cs | 6 +++--- .../src/System/Threading/Mutex.Windows.cs | 4 ++-- .../src/System/Threading/Semaphore.Windows.cs | 4 ++-- 18 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs index 53b0ad25573dd..0b428fa5a85a8 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs @@ -53,7 +53,7 @@ internal static unsafe string GetMessage(int errorCode, IntPtr moduleHandle) // We got back an error. If the error indicated that there wasn't enough room to store // the error message, then call FormatMessage again, but this time rather than passing in // a buffer, have the method allocate one, which we then need to free. - if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) + if (Marshal.GetLastPInvokeError() == ERROR_INSUFFICIENT_BUFFER) { IntPtr nativeMsgPtr = default; try diff --git a/src/libraries/Common/src/System/IO/Win32Marshal.cs b/src/libraries/Common/src/System/IO/Win32Marshal.cs index 2bb328411d993..150e81f88ae05 100644 --- a/src/libraries/Common/src/System/IO/Win32Marshal.cs +++ b/src/libraries/Common/src/System/IO/Win32Marshal.cs @@ -16,7 +16,7 @@ internal static class Win32Marshal /// including the specified path in the error message. /// internal static Exception GetExceptionForLastWin32Error(string? path = "") - => GetExceptionForWin32Error(Marshal.GetLastWin32Error(), path); + => GetExceptionForWin32Error(Marshal.GetLastPInvokeError(), path); /// /// Converts the specified Win32 error into a corresponding object, optionally diff --git a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.Windows.cs b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.Windows.cs index eed758083f17f..354384be17ec0 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.Windows.cs @@ -30,7 +30,7 @@ internal static int FillAttributeInfo(string path, ref Interop.Kernel32.WIN32_FI { if (!Interop.Kernel32.GetFileAttributesEx(path, Interop.Kernel32.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, ref data)) { - errorCode = Marshal.GetLastWin32Error(); + errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_ACCESS_DENIED) { // Files that are marked for deletion will not let you GetFileAttributes, @@ -43,7 +43,7 @@ internal static int FillAttributeInfo(string path, ref Interop.Kernel32.WIN32_FI { if (handle.IsInvalid) { - errorCode = Marshal.GetLastWin32Error(); + errorCode = Marshal.GetLastPInvokeError(); } else { diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Variables.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Variables.Windows.cs index 89e4bc7f45554..4531aa133b7ea 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Variables.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Variables.Windows.cs @@ -20,7 +20,7 @@ public static partial class Environment builder.EnsureCapacity((int)length); } - if (length == 0 && Marshal.GetLastWin32Error() == Interop.Errors.ERROR_ENVVAR_NOT_FOUND) + if (length == 0 && Marshal.GetLastPInvokeError() == Interop.Errors.ERROR_ENVVAR_NOT_FOUND) { builder.Dispose(); return null; @@ -34,7 +34,7 @@ private static void SetEnvironmentVariableCore(string variable, string? value) { if (!Interop.Kernel32.SetEnvironmentVariable(variable, value)) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); switch (errorCode) { case Interop.Errors.ERROR_ENVVAR_NOT_FOUND: diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs index ca769085b173f..a499d8984371e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Win32.cs @@ -56,7 +56,7 @@ private static void SetEnvironmentVariableFromRegistry(string variable, string? fixed (char* lParam = "Environment") { IntPtr r = Interop.User32.SendMessageTimeout(new IntPtr(Interop.User32.HWND_BROADCAST), Interop.User32.WM_SETTINGCHANGE, IntPtr.Zero, (IntPtr)lParam, 0, 1000, out IntPtr _); - Debug.Assert(r != IntPtr.Zero, "SetEnvironmentVariable failed: " + Marshal.GetLastWin32Error()); + Debug.Assert(r != IntPtr.Zero, "SetEnvironmentVariable failed: " + Marshal.GetLastPInvokeError()); } } } @@ -139,7 +139,7 @@ private static void GetUserName(ref ValueStringBuilder builder) uint size = 0; while (Interop.Secur32.GetUserNameExW(Interop.Secur32.NameSamCompatible, ref builder.GetPinnableReference(), ref size) == Interop.BOOLEAN.FALSE) { - if (Marshal.GetLastWin32Error() == Interop.Errors.ERROR_MORE_DATA) + if (Marshal.GetLastPInvokeError() == Interop.Errors.ERROR_MORE_DATA) { builder.EnsureCapacity(checked((int)size)); } @@ -186,7 +186,7 @@ public static string UserDomainName while (!Interop.Advapi32.LookupAccountNameW(null, ref builder.GetPinnableReference(), ref MemoryMarshal.GetReference(sid), ref sidLength, ref domainBuilder.GetPinnableReference(), ref length, out _)) { - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); // The docs don't call this out clearly, but experimenting shows that the error returned is the following. if (error != Interop.Errors.ERROR_INSUFFICIENT_BUFFER) diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs index b769f59cc2df2..ca9dfc0aa9711 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Windows.cs @@ -41,7 +41,7 @@ private static string CurrentDirectoryCore { if (!Interop.Kernel32.SetCurrentDirectory(value)) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); throw Win32Marshal.GetExceptionForWin32Error( errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND ? Interop.Errors.ERROR_PATH_NOT_FOUND : errorCode, value); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Nls.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Nls.cs index 396b3b0c699a5..1dc301b970aa5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Nls.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Nls.cs @@ -68,7 +68,7 @@ private static unsafe int FindStringOrdinal( Debug.Assert(ret >= -1 && ret <= source.Length); // SetLastError is only performed under debug builds. - Debug.Assert(ret >= 0 || Marshal.GetLastWin32Error() == Interop.Errors.ERROR_SUCCESS); + Debug.Assert(ret >= 0 || Marshal.GetLastPInvokeError() == Interop.Errors.ERROR_SUCCESS); return ret; } @@ -300,7 +300,7 @@ private unsafe int FindString( Debug.Assert(result >= -1 && result <= lpStringSource.Length); // SetLastError is only performed under debug builds. - Debug.Assert(result >= 0 || Marshal.GetLastWin32Error() == Interop.Errors.ERROR_SUCCESS); + Debug.Assert(result >= 0 || Marshal.GetLastPInvokeError() == Interop.Errors.ERROR_SUCCESS); return result; } @@ -506,7 +506,7 @@ private unsafe int NlsGetSortKey(ReadOnlySpan source, Span destinati // to allocate a temporary buffer large enough to hold intermediate state, // or the destination buffer being too small. - if (Marshal.GetLastWin32Error() == Interop.Errors.ERROR_INSUFFICIENT_BUFFER) + if (Marshal.GetLastPInvokeError() == Interop.Errors.ERROR_INSUFFICIENT_BUFFER) { ThrowHelper.ThrowArgumentException_DestinationTooShort(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Nls.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Nls.cs index 2e0e664520c04..baaa612cf1fb0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Nls.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.Nls.cs @@ -117,7 +117,7 @@ private uint NlsFlags [DoesNotReturn] private static void ThrowForZeroLength(bool unicode) { - int lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastPInvokeError(); throw new ArgumentException( lastError == Interop.Errors.ERROR_INVALID_NAME ? SR.Argument_IdnIllegalName : diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Nls.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Nls.cs index 76b0983c8f233..3abea57252989 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Nls.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/Normalization.Nls.cs @@ -25,7 +25,7 @@ private static unsafe bool NlsIsNormalized(string strInput, NormalizationForm no result = Interop.Normaliz.IsNormalizedString(normalizationForm, pInput, strInput.Length); } - int lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastPInvokeError(); switch (lastError) { case Interop.Errors.ERROR_SUCCESS: @@ -84,7 +84,7 @@ private static unsafe string NlsNormalize(string strInput, NormalizationForm nor { realLength = Interop.Normaliz.NormalizeString(normalizationForm, pInput, strInput.Length, pDest, buffer.Length); } - int lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastPInvokeError(); switch (lastError) { diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs index 377cde1305d74..ff479ce957f2c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs @@ -83,7 +83,7 @@ private static void GetFullPathName(ReadOnlySpan path, ref ValueStringBuil if (result == 0) { // Failure, get the error and throw - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == 0) errorCode = Interop.Errors.ERROR_BAD_PATHNAME; throw Win32Marshal.GetExceptionForWin32Error(errorCode, path.ToString()); @@ -185,7 +185,7 @@ internal static string TryExpandShortFileName(ref ValueStringBuilder outputBuild if (result == 0) { // Look to see if we couldn't find the file - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); if (error != Interop.Errors.ERROR_FILE_NOT_FOUND && error != Interop.Errors.ERROR_PATH_NOT_FOUND) { // Some other failure, give up diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs index 18079bb923ab6..f33e47b0fe15c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs @@ -176,7 +176,7 @@ private static SafeFileHandle ValidateFileHandle(SafeFileHandle fileHandle, stri // NT5 oddity - when trying to open "C:\" as a Win32FileStream, // we usually get ERROR_PATH_NOT_FOUND from the OS. We should // probably be consistent w/ every other directory. - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND && path!.Length == PathInternal.GetRootLength(path)) errorCode = Interop.Errors.ERROR_ACCESS_DENIED; @@ -229,7 +229,7 @@ internal static long Seek(SafeFileHandle handle, string? path, long offset, Seek internal static int GetLastWin32ErrorAndDisposeHandleIfInvalid(SafeFileHandle handle) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); // If ERROR_INVALID_HANDLE is returned, it doesn't suffice to set // the handle as invalid; the handle must also be closed. @@ -294,7 +294,7 @@ internal static void ValidateFileTypeForNonExtendedPaths(SafeFileHandle handle, if (fileType != Interop.Kernel32.FileTypes.FILE_TYPE_DISK) { int errorCode = fileType == Interop.Kernel32.FileTypes.FILE_TYPE_UNKNOWN - ? Marshal.GetLastWin32Error() + ? Marshal.GetLastPInvokeError() : Interop.Errors.ERROR_SUCCESS; handle.Dispose(); @@ -333,7 +333,7 @@ internal static unsafe void SetFileLength(SafeFileHandle handle, string? path, l &eofInfo, (uint)sizeof(Interop.Kernel32.FILE_END_OF_FILE_INFO))) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_INVALID_PARAMETER) throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_FileLengthTooBig); throw Win32Marshal.GetExceptionForWin32Error(errorCode, path); diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/Net5CompatFileStreamStrategy.CompletionSource.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/Net5CompatFileStreamStrategy.CompletionSource.Windows.cs index de5af4778a198..2c8a13feace0c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/Net5CompatFileStreamStrategy.CompletionSource.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/Net5CompatFileStreamStrategy.CompletionSource.Windows.cs @@ -200,7 +200,7 @@ private static void Cancel(object? state) if (!completionSource._strategy._fileHandle.IsInvalid && !Interop.Kernel32.CancelIoEx(completionSource._strategy._fileHandle, completionSource._overlapped)) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); // ERROR_NOT_FOUND is returned if CancelIoEx cannot find the request to cancel. // This probably means that the IO operation has completed. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index 4d022792ba7ee..91a337c264164 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -1173,7 +1173,7 @@ public static IntPtr GetFunctionPointerForDelegate(TDelegate d) where public static int GetHRForLastWin32Error() { - int dwLastError = GetLastWin32Error(); + int dwLastError = GetLastPInvokeError(); if ((dwLastError & 0x80000000) == 0x80000000) { return dwLastError; @@ -1279,10 +1279,5 @@ public static void InitHandle(SafeHandle safeHandle, IntPtr handle) // To help maximize performance of P/Invokes, don't check if safeHandle is null. safeHandle.SetHandle(handle); } - - public static int GetLastWin32Error() - { - return GetLastPInvokeError(); - } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Windows.cs index a8067c5f80c22..7dc9104ff4897 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.Windows.cs @@ -26,7 +26,7 @@ private void ProtectMemory() !_encrypted && !Interop.Crypt32.CryptProtectMemory(_buffer, (uint)_buffer.ByteLength, Interop.Crypt32.CRYPTPROTECTMEMORY_SAME_PROCESS)) { - throw new CryptographicException(Marshal.GetLastWin32Error()); + throw new CryptographicException(Marshal.GetLastPInvokeError()); } _encrypted = true; @@ -41,7 +41,7 @@ private void UnprotectMemory() _encrypted && !Interop.Crypt32.CryptUnprotectMemory(_buffer, (uint)_buffer.ByteLength, Interop.Crypt32.CRYPTPROTECTMEMORY_SAME_PROCESS)) { - throw new CryptographicException(Marshal.GetLastWin32Error()); + throw new CryptographicException(Marshal.GetLastPInvokeError()); } _encrypted = false; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Windows.cs index 73256bca70bca..20cb741435f0c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/EventWaitHandle.Windows.cs @@ -28,7 +28,7 @@ private void CreateEventCore(bool initialState, EventResetMode mode, string? nam SafeWaitHandle handle = Interop.Kernel32.CreateEventEx(IntPtr.Zero, name, eventFlags, AccessRights); - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (handle.IsInvalid) { handle.SetHandleAsInvalid(); @@ -54,7 +54,7 @@ private static OpenExistingResult OpenExistingWorker(string name, out EventWaitH if (myHandle.IsInvalid) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND || errorCode == Interop.Errors.ERROR_INVALID_NAME) return OpenExistingResult.NameNotFound; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs index 48564580ae126..c49e9dce80c38 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.Windows.cs @@ -26,7 +26,7 @@ private void Create(int maximumSignalCount) Interop.Kernel32.CreateIoCompletionPort(new IntPtr(-1), IntPtr.Zero, UIntPtr.Zero, maximumSignalCount); if (_completionPort == IntPtr.Zero) { - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); var exception = new OutOfMemoryException(); exception.HResult = error; throw exception; @@ -46,7 +46,7 @@ public bool WaitCore(int timeoutMs) Debug.Assert(timeoutMs >= -1); bool success = Interop.Kernel32.GetQueuedCompletionStatus(_completionPort, out int numberOfBytes, out UIntPtr completionKey, out IntPtr pointerToOverlapped, timeoutMs); - Debug.Assert(success || (Marshal.GetLastWin32Error() == WaitHandle.WaitTimeout)); + Debug.Assert(success || (Marshal.GetLastPInvokeError() == WaitHandle.WaitTimeout)); return success; } @@ -58,7 +58,7 @@ public void ReleaseCore(int count) { if (!Interop.Kernel32.PostQueuedCompletionStatus(_completionPort, 1, UIntPtr.Zero, IntPtr.Zero)) { - int lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastPInvokeError(); var exception = new OutOfMemoryException(); exception.HResult = lastError; throw exception; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs index cc444faf68a3f..48f23264a7f6c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Mutex.Windows.cs @@ -19,7 +19,7 @@ private void CreateMutexCore(bool initiallyOwned, string? name, out bool created { uint mutexFlags = initiallyOwned ? Interop.Kernel32.CREATE_MUTEX_INITIAL_OWNER : 0; SafeWaitHandle mutexHandle = Interop.Kernel32.CreateMutexEx(IntPtr.Zero, name, mutexFlags, AccessRights); - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (mutexHandle.IsInvalid) { @@ -60,7 +60,7 @@ private static OpenExistingResult OpenExistingWorker(string name, out Mutex? res if (myHandle.IsInvalid) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); #if TARGET_UNIX || TARGET_BROWSER if (errorCode == Interop.Errors.ERROR_FILENAME_EXCED_RANGE) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs index 9cef42fea0f5a..d92e9c9f88771 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs @@ -29,7 +29,7 @@ private void CreateSemaphoreCore(int initialCount, int maximumCount, string? nam #endif SafeWaitHandle myHandle = Interop.Kernel32.CreateSemaphoreEx(IntPtr.Zero, initialCount, maximumCount, name, 0, AccessRights); - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (myHandle.IsInvalid) { if (!string.IsNullOrEmpty(name) && errorCode == Interop.Errors.ERROR_INVALID_HANDLE) @@ -56,7 +56,7 @@ private static OpenExistingResult OpenExistingWorker(string name, out Semaphore? if (myHandle.IsInvalid) { result = null; - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND || errorCode == Interop.Errors.ERROR_INVALID_NAME) return OpenExistingResult.NameNotFound; From b7abc3c437cec0e3ebf5be44890723f518cc49cc Mon Sep 17 00:00:00 2001 From: Kareem Zedan Date: Wed, 28 Apr 2021 20:07:34 +0100 Subject: [PATCH 2/6] remove problem changes --- .../src/Interop/Windows/Kernel32/Interop.FormatMessage.cs | 2 +- src/libraries/Common/src/System/IO/Win32Marshal.cs | 2 +- .../src/System/IO/PathHelper.Windows.cs | 4 ++-- .../src/System/Runtime/InteropServices/Marshal.cs | 5 +++++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs index 0b428fa5a85a8..53b0ad25573dd 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs @@ -53,7 +53,7 @@ internal static unsafe string GetMessage(int errorCode, IntPtr moduleHandle) // We got back an error. If the error indicated that there wasn't enough room to store // the error message, then call FormatMessage again, but this time rather than passing in // a buffer, have the method allocate one, which we then need to free. - if (Marshal.GetLastPInvokeError() == ERROR_INSUFFICIENT_BUFFER) + if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) { IntPtr nativeMsgPtr = default; try diff --git a/src/libraries/Common/src/System/IO/Win32Marshal.cs b/src/libraries/Common/src/System/IO/Win32Marshal.cs index 150e81f88ae05..2bb328411d993 100644 --- a/src/libraries/Common/src/System/IO/Win32Marshal.cs +++ b/src/libraries/Common/src/System/IO/Win32Marshal.cs @@ -16,7 +16,7 @@ internal static class Win32Marshal /// including the specified path in the error message. /// internal static Exception GetExceptionForLastWin32Error(string? path = "") - => GetExceptionForWin32Error(Marshal.GetLastPInvokeError(), path); + => GetExceptionForWin32Error(Marshal.GetLastWin32Error(), path); /// /// Converts the specified Win32 error into a corresponding object, optionally diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs index ff479ce957f2c..377cde1305d74 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs @@ -83,7 +83,7 @@ private static void GetFullPathName(ReadOnlySpan path, ref ValueStringBuil if (result == 0) { // Failure, get the error and throw - int errorCode = Marshal.GetLastPInvokeError(); + int errorCode = Marshal.GetLastWin32Error(); if (errorCode == 0) errorCode = Interop.Errors.ERROR_BAD_PATHNAME; throw Win32Marshal.GetExceptionForWin32Error(errorCode, path.ToString()); @@ -185,7 +185,7 @@ internal static string TryExpandShortFileName(ref ValueStringBuilder outputBuild if (result == 0) { // Look to see if we couldn't find the file - int error = Marshal.GetLastPInvokeError(); + int error = Marshal.GetLastWin32Error(); if (error != Interop.Errors.ERROR_FILE_NOT_FOUND && error != Interop.Errors.ERROR_PATH_NOT_FOUND) { // Some other failure, give up diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index 91a337c264164..64269561d7e01 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -1279,5 +1279,10 @@ public static void InitHandle(SafeHandle safeHandle, IntPtr handle) // To help maximize performance of P/Invokes, don't check if safeHandle is null. safeHandle.SetHandle(handle); } + + public static int GetLastWin32Error() + { + return GetLastPInvokeError(); + } } } From 392c4f5a937fb2600e21b1b28a0ec83841029f70 Mon Sep 17 00:00:00 2001 From: Kareem Zedan Date: Mon, 3 May 2021 18:01:09 +0100 Subject: [PATCH 3/6] replacing GetLastWin32Error with GetLastPInvokeError in remaining assemblies --- .../Windows/Kernel32/Interop.FormatMessage.cs | 4 + .../Common/src/System/IO/Win32Marshal.cs | 6 +- .../System.IO.FileSystem.AccessControl.sln | 53 +++++---- .../System.IO.FileSystem.AccessControl.csproj | 108 ++++++------------ .../System.Net.Http.WinHttpHandler.sln | 46 ++++---- .../src/System.Net.Http.WinHttpHandler.csproj | 2 +- .../src/System/IO/PathHelper.Windows.cs | 8 ++ .../src/ApiCompatBaseline.txt | 1 + ...em.Security.Cryptography.ProtectedData.sln | 35 ++++-- ...Security.Cryptography.ProtectedData.csproj | 34 +++--- .../Security/Cryptography/ProtectedData.cs | 7 +- .../src/System.Text.Json.csproj | 2 +- 12 files changed, 155 insertions(+), 151 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs index 53b0ad25573dd..4c780c0069643 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs @@ -53,7 +53,11 @@ internal static unsafe string GetMessage(int errorCode, IntPtr moduleHandle) // We got back an error. If the error indicated that there wasn't enough room to store // the error message, then call FormatMessage again, but this time rather than passing in // a buffer, have the method allocate one, which we then need to free. +#if NET6_0 + if (Marshal.GetLastPInvokeError() == ERROR_INSUFFICIENT_BUFFER) +#else if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) +#endif { IntPtr nativeMsgPtr = default; try diff --git a/src/libraries/Common/src/System/IO/Win32Marshal.cs b/src/libraries/Common/src/System/IO/Win32Marshal.cs index 2bb328411d993..f062429fd767d 100644 --- a/src/libraries/Common/src/System/IO/Win32Marshal.cs +++ b/src/libraries/Common/src/System/IO/Win32Marshal.cs @@ -15,9 +15,13 @@ internal static class Win32Marshal /// Converts, resetting it, the last Win32 error into a corresponding object, optionally /// including the specified path in the error message. /// +#if NET6_0 internal static Exception GetExceptionForLastWin32Error(string? path = "") + => GetExceptionForWin32Error(Marshal.GetLastPInvokeError(), path); +#else + internal static Exception GetExceptionForLastWin32Error(string? path = "") => GetExceptionForWin32Error(Marshal.GetLastWin32Error(), path); - +#endif /// /// Converts the specified Win32 error into a corresponding object, optionally /// including the specified path in the error message. diff --git a/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln b/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln index 0982a373b5cef..c753a74327b2d 100644 --- a/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln +++ b/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln @@ -1,4 +1,8 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{18FD488A-2A3F-4B40-B65D-7108688D350F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj", "{BC0B86CC-54C1-450F-A710-13A66571EEBE}" @@ -41,27 +45,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{A9FD5D03-151 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices", "..\System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj", "{482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}" +EndProject Global - GlobalSection(NestedProjects) = preSolution - {18FD488A-2A3F-4B40-B65D-7108688D350F} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} - {9EB99AA1-EE31-41AC-B3E6-DCD7A01F17F2} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} - {BC0B86CC-54C1-450F-A710-13A66571EEBE} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {071FC282-9840-4920-B0FD-BE778449B5FF} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {C0B560B2-72A0-41B2-82D5-34EF31719AD7} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {D7E6A261-C80A-4E51-BCDD-85DD595866B9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {3709D2F4-5495-447A-81D1-D022B5A22DF9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {1AC0BFF9-2F4E-4E6A-8A5A-89DFF3AE2C74} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {37F8ED93-FD45-4941-B83E-84D278B8EA83} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {EAAF9D04-EB06-48C5-B678-662C777FBC7D} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {F33F1171-273A-4BC3-B138-25E5E7118186} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {4EF591E4-175E-494D-8191-15C2D6C6E2E6} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {35D57A83-8A9D-4531-BF0D-EA1BCA62D475} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {0EB6C67A-FD15-48A6-A608-F7E27DA8DB7E} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {62B4CB1C-16EE-4B2F-9FF1-DF2770A056F9} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {87E03C4D-FFE2-43AD-9CFE-BB67A2448186} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {4C5EE1EB-EACF-4A3A-88EC-CA7B3B7D50BA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -139,10 +125,35 @@ Global {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA}.Debug|Any CPU.Build.0 = Debug|Any CPU {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA}.Release|Any CPU.ActiveCfg = Release|Any CPU {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA}.Release|Any CPU.Build.0 = Release|Any CPU + {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {18FD488A-2A3F-4B40-B65D-7108688D350F} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} + {BC0B86CC-54C1-450F-A710-13A66571EEBE} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {071FC282-9840-4920-B0FD-BE778449B5FF} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {4EF591E4-175E-494D-8191-15C2D6C6E2E6} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {C0B560B2-72A0-41B2-82D5-34EF31719AD7} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {D7E6A261-C80A-4E51-BCDD-85DD595866B9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {35D57A83-8A9D-4531-BF0D-EA1BCA62D475} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {9EB99AA1-EE31-41AC-B3E6-DCD7A01F17F2} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} + {3709D2F4-5495-447A-81D1-D022B5A22DF9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {0EB6C67A-FD15-48A6-A608-F7E27DA8DB7E} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {1AC0BFF9-2F4E-4E6A-8A5A-89DFF3AE2C74} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {62B4CB1C-16EE-4B2F-9FF1-DF2770A056F9} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {37F8ED93-FD45-4941-B83E-84D278B8EA83} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {87E03C4D-FFE2-43AD-9CFE-BB67A2448186} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {EAAF9D04-EB06-48C5-B678-662C777FBC7D} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {4C5EE1EB-EACF-4A3A-88EC-CA7B3B7D50BA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {F33F1171-273A-4BC3-B138-25E5E7118186} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {246C2EDA-448E-4E76-B97A-BD93DC6883A7} EndGlobalSection diff --git a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj index 503971f5c7a22..67ba73a1079cc 100644 --- a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj +++ b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj @@ -11,15 +11,12 @@ SR.PlatformNotSupported_AccessControl - + - - + + @@ -28,72 +25,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln b/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln index f9b2b579d78fd..b5e4176ba3658 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln +++ b/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln @@ -1,4 +1,8 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{49FC63FA-3E81-4335-91CF-B5056E007343}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bcl.AsyncInterfaces", "..\Microsoft.Bcl.AsyncInterfaces\ref\Microsoft.Bcl.AsyncInterfaces.csproj", "{D18082CB-C337-473B-8AC3-5FCC312F90C6}" @@ -42,26 +46,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2E71EAE8-4677-4E28-A2A3-09AD42E702EC}" EndProject Global - GlobalSection(NestedProjects) = preSolution - {49FC63FA-3E81-4335-91CF-B5056E007343} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} - {E9D5AB56-2597-42E0-BE81-C00CC63D1FB3} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} - {090BA6CA-F661-4BDE-9663-65F8231DDB1D} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} - {D18082CB-C337-473B-8AC3-5FCC312F90C6} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {845F6CBC-8663-446C-B874-9BE54D2EF6EC} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {6FD15E9F-9E3B-494C-8F7F-67C9641A3FDB} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {B3C3E9D6-EEB3-4DE1-9B35-C0984474E522} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {E2311DD8-2E5E-4DD7-840F-237A8F77A311} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {B294FD03-AC49-4235-863F-5966BAB0C84D} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {6408B084-5213-4955-8262-6740B96045B2} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {4BA25EC1-B76B-4410-AF2D-A54B90FAB404} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {7EF13CC5-C714-4C0F-990F-C0884B92A9A1} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {E6A8B90B-69CD-4B0D-8A33-F208A3169674} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {DE2A69CC-4962-4BF6-A714-41A87A6C045B} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {28C24BF8-8E08-485F-8EEE-817EB847774C} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {488643D8-1F81-4998-8A6C-E00978977AD2} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {BACC5257-6CA8-45C7-970F-C8D501DA59AB} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {E470810A-BAF2-4B3C-92CB-72007B7F1B6A} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -143,6 +127,26 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {49FC63FA-3E81-4335-91CF-B5056E007343} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} + {D18082CB-C337-473B-8AC3-5FCC312F90C6} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {4BA25EC1-B76B-4410-AF2D-A54B90FAB404} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {845F6CBC-8663-446C-B874-9BE54D2EF6EC} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {6FD15E9F-9E3B-494C-8F7F-67C9641A3FDB} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {7EF13CC5-C714-4C0F-990F-C0884B92A9A1} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {E6A8B90B-69CD-4B0D-8A33-F208A3169674} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {B3C3E9D6-EEB3-4DE1-9B35-C0984474E522} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {DE2A69CC-4962-4BF6-A714-41A87A6C045B} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {E9D5AB56-2597-42E0-BE81-C00CC63D1FB3} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} + {090BA6CA-F661-4BDE-9663-65F8231DDB1D} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} + {E2311DD8-2E5E-4DD7-840F-237A8F77A311} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {28C24BF8-8E08-485F-8EEE-817EB847774C} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {B294FD03-AC49-4235-863F-5966BAB0C84D} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {6408B084-5213-4955-8262-6740B96045B2} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {488643D8-1F81-4998-8A6C-E00978977AD2} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {BACC5257-6CA8-45C7-970F-C8D501DA59AB} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {E470810A-BAF2-4B3C-92CB-72007B7F1B6A} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F5BAF3DD-D05C-4DCC-BB36-16645CA1F151} EndGlobalSection diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj index 3a1719f2c0d6c..4329efc36955b 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj @@ -1,4 +1,4 @@ - + true netstandard2.0-windows;netstandard2.0;netstandard2.1-windows;netstandard2.1;net461-windows diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs index 377cde1305d74..c51ea851d823b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs @@ -83,7 +83,11 @@ private static void GetFullPathName(ReadOnlySpan path, ref ValueStringBuil if (result == 0) { // Failure, get the error and throw +#if NET6_0 + int errorCode = Marshal.GetLastPInvokeError(); +#else int errorCode = Marshal.GetLastWin32Error(); +#endif if (errorCode == 0) errorCode = Interop.Errors.ERROR_BAD_PATHNAME; throw Win32Marshal.GetExceptionForWin32Error(errorCode, path.ToString()); @@ -185,7 +189,11 @@ internal static string TryExpandShortFileName(ref ValueStringBuilder outputBuild if (result == 0) { // Look to see if we couldn't find the file +#if NET6_0 + int error = Marshal.GetLastPInvokeError(); +#else int error = Marshal.GetLastWin32Error(); +#endif if (error != Interop.Errors.ERROR_FILE_NOT_FOUND && error != Interop.Errors.ERROR_PATH_NOT_FOUND) { // Some other failure, give up diff --git a/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt b/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt index c895342411f1b..7ba8b04f23625 100644 --- a/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt +++ b/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt @@ -1,3 +1,4 @@ +Compat issues with assembly System.Runtime.CompilerServices.Unsafe: CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.AllowNullAttribute' exists on parameter 'left' on member 'System.Runtime.CompilerServices.Unsafe.AreSame(T, T)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.AllowNullAttribute' exists on parameter 'right' on member 'System.Runtime.CompilerServices.Unsafe.AreSame(T, T)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.AllowNullAttribute' exists on parameter 'origin' on member 'System.Runtime.CompilerServices.Unsafe.ByteOffset(T, T)' in the contract but not the implementation. diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln b/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln index f405d1179d45d..fe0c9a61caf1f 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln +++ b/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln @@ -1,4 +1,8 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{21CC9F35-ACAA-4452-BE92-BBAE2E927B20}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj", "{4248C69F-DFF2-4E47-9749-E12D1312F5D5}" @@ -23,18 +27,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{E71CB63B-6EB EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{60F975CB-2CC9-43E1-804B-9FB4142F49E8}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices", "..\System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj", "{C9FBEDE9-6A21-4696-8259-79C0B885BB79}" +EndProject Global - GlobalSection(NestedProjects) = preSolution - {21CC9F35-ACAA-4452-BE92-BBAE2E927B20} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} - {3A6C62D5-EFCA-4119-BC60-C917533848A8} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} - {4248C69F-DFF2-4E47-9749-E12D1312F5D5} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {179902DA-28E6-42F5-BA2D-905BEC68A32C} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {C25543F0-E445-45AF-809D-388DF6496520} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {E40DBC0E-386A-4B32-8DCE-9FE13EAD47BE} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {B3C3180D-31E8-4225-8A5D-6765945C9647} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {90042C2E-6AD9-4BFF-B7CA-8E6BF9B3D3C7} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} - {7773DB7A-494F-4508-9471-F737FDC7661E} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -76,10 +71,26 @@ Global {B3C3180D-31E8-4225-8A5D-6765945C9647}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3C3180D-31E8-4225-8A5D-6765945C9647}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3C3180D-31E8-4225-8A5D-6765945C9647}.Release|Any CPU.Build.0 = Release|Any CPU + {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {21CC9F35-ACAA-4452-BE92-BBAE2E927B20} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} + {4248C69F-DFF2-4E47-9749-E12D1312F5D5} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {179902DA-28E6-42F5-BA2D-905BEC68A32C} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {90042C2E-6AD9-4BFF-B7CA-8E6BF9B3D3C7} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} + {C25543F0-E445-45AF-809D-388DF6496520} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {E40DBC0E-386A-4B32-8DCE-9FE13EAD47BE} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {7773DB7A-494F-4508-9471-F737FDC7661E} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} + {3A6C62D5-EFCA-4119-BC60-C917533848A8} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} + {B3C3180D-31E8-4225-8A5D-6765945C9647} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {C9FBEDE9-6A21-4696-8259-79C0B885BB79} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FB101479-5EAB-495B-ACF3-4B6FC3F830EF} EndGlobalSection diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj index 58751f8256471..729c900f80c64 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj +++ b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj @@ -1,7 +1,7 @@ true - netstandard2.0-windows;net461-windows;netstandard2.0 + $(NetCoreAppCurrent);netstandard2.0;net461-windows; enable @@ -13,24 +13,15 @@ - - - - - - - - - + + + + + + + + + @@ -39,4 +30,7 @@ - \ No newline at end of file + + + + diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs b/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs index 0e6b65bea1664..38190ce7ac79b 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs +++ b/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs @@ -1,9 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Runtime.InteropServices; - using Internal.Cryptography; +using System.Runtime.InteropServices; using DATA_BLOB = Interop.Crypt32.DATA_BLOB; using CryptProtectDataFlags = Interop.Crypt32.CryptProtectDataFlags; @@ -63,7 +62,11 @@ private static byte[] ProtectOrUnprotect(byte[] inputData, byte[]? optionalEntro Interop.Crypt32.CryptUnprotectData(ref userDataBlob, IntPtr.Zero, ref optionalEntropyBlob, IntPtr.Zero, IntPtr.Zero, flags, out outputBlob); if (!success) { +#if NET6_0 + int lastWin32Error = Marshal.GetLastPInvokeError(); +#else int lastWin32Error = Marshal.GetLastWin32Error(); +#endif if (protect && ErrorMayBeCausedByUnloadedProfile(lastWin32Error)) throw new CryptographicException(SR.Cryptography_DpApi_ProfileMayNotBeLoaded); else diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index da3e843491517..5d2d1eefbda6b 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -1,4 +1,4 @@ - + true $(NetCoreAppCurrent);netstandard2.0;netcoreapp3.0;net461 From 3b3c46ef1d7996c2fd0c37de9ab3cfb8fc172d7d Mon Sep 17 00:00:00 2001 From: Kareem Zedan Date: Mon, 3 May 2021 19:15:44 +0100 Subject: [PATCH 4/6] removing non change related changes --- .../Crypt32/Interop.CryptProtectData.cs | 2 +- .../System.IO.FileSystem.AccessControl.sln | 6 +- .../System.IO.FileSystem.AccessControl.csproj | 110 ++++++++++++------ .../System.Net.Http.WinHttpHandler.sln | 6 +- .../src/ApiCompatBaseline.txt | 1 - ...em.Security.Cryptography.ProtectedData.sln | 6 +- ...Security.Cryptography.ProtectedData.csproj | 29 +++-- .../Security/Cryptography/ProtectedData.cs | 3 +- 8 files changed, 98 insertions(+), 65 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs index bf6cc60b98503..6fab3a93fad5f 100644 --- a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs +++ b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs @@ -13,7 +13,7 @@ internal static partial class Crypt32 [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool CryptProtectData( [In] ref DATA_BLOB pDataIn, - [In] string szDataDescr, + [In] string? szDataDescr, [In] ref DATA_BLOB pOptionalEntropy, [In] IntPtr pvReserved, [In] IntPtr pPromptStruct, diff --git a/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln b/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln index c753a74327b2d..40f2e6c07eb21 100644 --- a/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln +++ b/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln @@ -1,8 +1,4 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31205.134 -MinimumVisualStudioVersion = 10.0.40219.1 +Microsoft Visual Studio Solution File, Format Version 12.00 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{18FD488A-2A3F-4B40-B65D-7108688D350F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj", "{BC0B86CC-54C1-450F-A710-13A66571EEBE}" diff --git a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj index 67ba73a1079cc..496aa1613ff3d 100644 --- a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj +++ b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent)-windows;netstandard2.0;netstandard2.0-windows;net461-windows true @@ -11,12 +11,15 @@ SR.PlatformNotSupported_AccessControl - + - - + + @@ -25,39 +28,72 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln b/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln index b5e4176ba3658..223a6b42197bf 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln +++ b/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln @@ -1,8 +1,4 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31205.134 -MinimumVisualStudioVersion = 10.0.40219.1 +Microsoft Visual Studio Solution File, Format Version 12.00 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{49FC63FA-3E81-4335-91CF-B5056E007343}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bcl.AsyncInterfaces", "..\Microsoft.Bcl.AsyncInterfaces\ref\Microsoft.Bcl.AsyncInterfaces.csproj", "{D18082CB-C337-473B-8AC3-5FCC312F90C6}" diff --git a/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt b/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt index 7ba8b04f23625..c895342411f1b 100644 --- a/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt +++ b/src/libraries/System.Runtime.CompilerServices.Unsafe/src/ApiCompatBaseline.txt @@ -1,4 +1,3 @@ -Compat issues with assembly System.Runtime.CompilerServices.Unsafe: CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.AllowNullAttribute' exists on parameter 'left' on member 'System.Runtime.CompilerServices.Unsafe.AreSame(T, T)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.AllowNullAttribute' exists on parameter 'right' on member 'System.Runtime.CompilerServices.Unsafe.AreSame(T, T)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.AllowNullAttribute' exists on parameter 'origin' on member 'System.Runtime.CompilerServices.Unsafe.ByteOffset(T, T)' in the contract but not the implementation. diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln b/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln index fe0c9a61caf1f..0be65f24b8c9a 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln +++ b/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln @@ -1,8 +1,4 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31205.134 -MinimumVisualStudioVersion = 10.0.40219.1 +Microsoft Visual Studio Solution File, Format Version 12.00 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{21CC9F35-ACAA-4452-BE92-BBAE2E927B20}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj", "{4248C69F-DFF2-4E47-9749-E12D1312F5D5}" diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj index 729c900f80c64..946ac31b8ace4 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj +++ b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj @@ -1,7 +1,7 @@ true - $(NetCoreAppCurrent);netstandard2.0;net461-windows; + $(NetCoreAppCurrent);netstandard2.0-windows;net461-windows;netstandard2.0 enable @@ -13,15 +13,24 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs b/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs index 38190ce7ac79b..4dfb1d9305b68 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs +++ b/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs @@ -1,9 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Internal.Cryptography; using System.Runtime.InteropServices; +using Internal.Cryptography; + using DATA_BLOB = Interop.Crypt32.DATA_BLOB; using CryptProtectDataFlags = Interop.Crypt32.CryptProtectDataFlags; From f814d89c0b38c46d2d37e4ec6743fd0e8006f639 Mon Sep 17 00:00:00 2001 From: Kareem Zedan Date: Wed, 5 May 2021 22:52:09 +0100 Subject: [PATCH 5/6] replace GetLastWin32Error with GetLastPInvokeError in assemblies outside system.private.corelib --- .../Crypt32/Interop.CryptProtectData.cs | 2 +- .../Windows/Kernel32/Interop.FormatMessage.cs | 4 -- .../Common/src/System/IO/Win32Marshal.cs | 6 +- .../System/ComponentModel/Win32Exception.cs | 6 +- .../tests/Win32ExceptionTests.cs | 2 +- .../src/System/ConsolePal.Windows.cs | 58 +++++++++---------- .../System.IO.FileSystem.AccessControl.sln | 47 +++++++-------- .../System.IO.FileSystem.AccessControl.csproj | 2 +- .../src/System/IO/DriveInfo.Windows.cs | 2 +- .../src/System/IO/Error.cs | 2 +- .../src/System/IO/FileSystemWatcher.OSX.cs | 2 +- .../tests/PortedCommon/IOServices.cs | 4 +- .../PortedCommon/ReparsePointUtilities.cs | 6 +- .../MemoryMappedFile.Windows.cs | 6 +- .../MemoryMappedView.Windows.cs | 6 +- .../IO/Pipes/NamedPipeClientStream.Windows.cs | 8 +-- .../IO/Pipes/NamedPipeServerStream.Win32.cs | 2 +- .../IO/Pipes/NamedPipeServerStream.Windows.cs | 10 ++-- .../System/IO/Pipes/PipeCompletionSource.cs | 2 +- .../src/System/IO/Pipes/PipeStream.Windows.cs | 16 ++--- .../tests/InteropTest.Windows.cs | 2 +- .../System.Net.Http.WinHttpHandler.sln | 40 ++++++------- .../src/System.Net.Http.WinHttpHandler.csproj | 2 +- .../src/System/Net/HttpListenerException.cs | 2 +- .../Windows/HttpListenerSession.Windows.cs | 2 +- .../Net/NetworkInformation/Ping.Windows.cs | 2 +- .../src/System/Net/SocketException.Windows.cs | 2 +- .../Net/CertificateValidationPal.Windows.cs | 2 +- .../Net/WebSockets/WebSocketException.cs | 2 +- .../tests/WebSocketExceptionTests.cs | 2 +- .../src/System/IO/PathHelper.Windows.cs | 8 --- .../tests/System/EnvironmentTests.cs | 2 +- .../tests/SafeHandle.cs | 2 +- .../InteropServices/Marshal/LastErrorTests.cs | 4 +- .../Cryptography/CapiHelper.Windows.cs | 2 +- ...em.Security.Cryptography.ProtectedData.sln | 29 ++++------ ...Security.Cryptography.ProtectedData.csproj | 7 +-- .../Security/Cryptography/ProtectedData.cs | 4 -- .../src/System.Text.Json.csproj | 2 +- .../ThreadPoolBoundHandle_IntegrationTests.cs | 12 ++-- 40 files changed, 143 insertions(+), 180 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs index 6fab3a93fad5f..bf6cc60b98503 100644 --- a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs +++ b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptProtectData.cs @@ -13,7 +13,7 @@ internal static partial class Crypt32 [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool CryptProtectData( [In] ref DATA_BLOB pDataIn, - [In] string? szDataDescr, + [In] string szDataDescr, [In] ref DATA_BLOB pOptionalEntropy, [In] IntPtr pvReserved, [In] IntPtr pPromptStruct, diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs index 4c780c0069643..53b0ad25573dd 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs @@ -53,11 +53,7 @@ internal static unsafe string GetMessage(int errorCode, IntPtr moduleHandle) // We got back an error. If the error indicated that there wasn't enough room to store // the error message, then call FormatMessage again, but this time rather than passing in // a buffer, have the method allocate one, which we then need to free. -#if NET6_0 - if (Marshal.GetLastPInvokeError() == ERROR_INSUFFICIENT_BUFFER) -#else if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) -#endif { IntPtr nativeMsgPtr = default; try diff --git a/src/libraries/Common/src/System/IO/Win32Marshal.cs b/src/libraries/Common/src/System/IO/Win32Marshal.cs index f062429fd767d..2bb328411d993 100644 --- a/src/libraries/Common/src/System/IO/Win32Marshal.cs +++ b/src/libraries/Common/src/System/IO/Win32Marshal.cs @@ -15,13 +15,9 @@ internal static class Win32Marshal /// Converts, resetting it, the last Win32 error into a corresponding object, optionally /// including the specified path in the error message. /// -#if NET6_0 internal static Exception GetExceptionForLastWin32Error(string? path = "") - => GetExceptionForWin32Error(Marshal.GetLastPInvokeError(), path); -#else - internal static Exception GetExceptionForLastWin32Error(string? path = "") => GetExceptionForWin32Error(Marshal.GetLastWin32Error(), path); -#endif + /// /// Converts the specified Win32 error into a corresponding object, optionally /// including the specified path in the error message. diff --git a/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs b/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs index a2b1644108098..bf78cbc03c926 100644 --- a/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs +++ b/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs @@ -21,7 +21,7 @@ public partial class Win32Exception : ExternalException, ISerializable /// Initializes a new instance of the class with the last Win32 error /// that occurred. /// - public Win32Exception() : this(Marshal.GetLastWin32Error()) + public Win32Exception() : this(Marshal.GetLastPInvokeError()) { } @@ -43,7 +43,7 @@ public Win32Exception(int error, string? message) : base(message) /// /// Initializes a new instance of the Exception class with a specified error message. /// - public Win32Exception(string? message) : this(Marshal.GetLastWin32Error(), message) + public Win32Exception(string? message) : this(Marshal.GetLastPInvokeError(), message) { } @@ -53,7 +53,7 @@ public Win32Exception(string? message) : this(Marshal.GetLastWin32Error(), messa /// public Win32Exception(string? message, Exception? innerException) : base(message, innerException) { - NativeErrorCode = Marshal.GetLastWin32Error(); + NativeErrorCode = Marshal.GetLastPInvokeError(); } protected Win32Exception(SerializationInfo info, StreamingContext context) : base(info, context) diff --git a/src/libraries/Microsoft.Win32.Primitives/tests/Win32ExceptionTests.cs b/src/libraries/Microsoft.Win32.Primitives/tests/Win32ExceptionTests.cs index 04a1dfca13be1..27bdd0860086b 100644 --- a/src/libraries/Microsoft.Win32.Primitives/tests/Win32ExceptionTests.cs +++ b/src/libraries/Microsoft.Win32.Primitives/tests/Win32ExceptionTests.cs @@ -38,7 +38,7 @@ private static bool IsExceptionMessageLong(int errorCode) null); if (result == 0) { - return (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER); + return (Marshal.GetLastPInvokeError() == ERROR_INSUFFICIENT_BUFFER); } return false; diff --git a/src/libraries/System.Console/src/System/ConsolePal.Windows.cs b/src/libraries/System.Console/src/System/ConsolePal.Windows.cs index dd74a7d826e97..95cebc12c4887 100644 --- a/src/libraries/System.Console/src/System/ConsolePal.Windows.cs +++ b/src/libraries/System.Console/src/System/ConsolePal.Windows.cs @@ -109,7 +109,7 @@ public static void SetConsoleInputEncoding(Encoding enc) if (enc.CodePage != UnicodeCodePage) { if (!Interop.Kernel32.SetConsoleCP(enc.CodePage)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } } @@ -123,7 +123,7 @@ public static void SetConsoleOutputEncoding(Encoding enc) if (enc.CodePage != UnicodeCodePage) { if (!Interop.Kernel32.SetConsoleOutputCP(enc.CodePage)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } } @@ -280,7 +280,7 @@ public static bool KeyAvailable bool r = Interop.Kernel32.PeekConsoleInput(InputHandle, out ir, 1, out numEventsRead); if (!r) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE) throw new InvalidOperationException(SR.InvalidOperation_ConsoleKeyAvailableOnFile); throw Win32Marshal.GetExceptionForWin32Error(errorCode, "stdin"); @@ -295,7 +295,7 @@ public static bool KeyAvailable r = Interop.Kernel32.ReadConsoleInput(InputHandle, out ir, 1, out numEventsRead); if (!r) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } else { @@ -413,7 +413,7 @@ public static bool TreatControlCAsInput int mode = 0; if (!Interop.Kernel32.GetConsoleMode(handle, out mode)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); return (mode & Interop.Kernel32.ENABLE_PROCESSED_INPUT) == 0; } @@ -425,7 +425,7 @@ public static bool TreatControlCAsInput int mode = 0; if (!Interop.Kernel32.GetConsoleMode(handle, out mode)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); if (value) { @@ -437,7 +437,7 @@ public static bool TreatControlCAsInput } if (!Interop.Kernel32.SetConsoleMode(handle, mode)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } } @@ -534,7 +534,7 @@ public static int CursorSize { Interop.Kernel32.CONSOLE_CURSOR_INFO cci; if (!Interop.Kernel32.GetConsoleCursorInfo(OutputHandle, out cci)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); return cci.dwSize; } @@ -546,11 +546,11 @@ public static int CursorSize Interop.Kernel32.CONSOLE_CURSOR_INFO cci; if (!Interop.Kernel32.GetConsoleCursorInfo(OutputHandle, out cci)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); cci.dwSize = value; if (!Interop.Kernel32.SetConsoleCursorInfo(OutputHandle, ref cci)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } } @@ -560,7 +560,7 @@ public static bool CursorVisible { Interop.Kernel32.CONSOLE_CURSOR_INFO cci; if (!Interop.Kernel32.GetConsoleCursorInfo(OutputHandle, out cci)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); return cci.bVisible; } @@ -568,11 +568,11 @@ public static bool CursorVisible { Interop.Kernel32.CONSOLE_CURSOR_INFO cci; if (!Interop.Kernel32.GetConsoleCursorInfo(OutputHandle, out cci)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); cci.bVisible = value; if (!Interop.Kernel32.SetConsoleCursorInfo(OutputHandle, ref cci)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } } @@ -604,7 +604,7 @@ public static unsafe string Title if (result == 0) { - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); switch (error) { case Interop.Errors.ERROR_INSUFFICIENT_BUFFER: @@ -639,7 +639,7 @@ public static unsafe string Title set { if (!Interop.Kernel32.SetConsoleTitle(value)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } } @@ -715,7 +715,7 @@ public static unsafe void MoveBufferArea(int sourceLeft, int sourceTop, fixed (Interop.Kernel32.CHAR_INFO* pCharInfo = data) r = Interop.Kernel32.ReadConsoleOutput(OutputHandle, pCharInfo, bufferSize, bufferCoord, ref readRegion); if (!r) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); // Overwrite old section Interop.Kernel32.COORD writeCoord = default; @@ -730,11 +730,11 @@ public static unsafe void MoveBufferArea(int sourceLeft, int sourceTop, r = Interop.Kernel32.FillConsoleOutputCharacter(OutputHandle, sourceChar, sourceWidth, writeCoord, out numWritten); Debug.Assert(numWritten == sourceWidth, "FillConsoleOutputCharacter wrote the wrong number of chars!"); if (!r) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); r = Interop.Kernel32.FillConsoleOutputAttribute(OutputHandle, attr, sourceWidth, writeCoord, out numWritten); if (!r) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } // Write text to new location @@ -771,7 +771,7 @@ public static void Clear() success = Interop.Kernel32.FillConsoleOutputCharacter(hConsole, ' ', conSize, coordScreen, out numCellsWritten); if (!success) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); // now set the buffer's attributes accordingly @@ -779,13 +779,13 @@ public static void Clear() success = Interop.Kernel32.FillConsoleOutputAttribute(hConsole, csbi.wAttributes, conSize, coordScreen, out numCellsWritten); if (!success) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); // put the cursor at (0, 0) success = Interop.Kernel32.SetConsoleCursorPosition(hConsole, coordScreen); if (!success) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } public static void SetCursorPosition(int left, int top) @@ -797,7 +797,7 @@ public static void SetCursorPosition(int left, int top) if (!Interop.Kernel32.SetConsoleCursorPosition(hConsole, coords)) { // Give a nice error message for out of range sizes - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO csbi = GetBufferInfo(); if (left >= csbi.dwSize.X) throw new ArgumentOutOfRangeException(nameof(left), left, SR.ArgumentOutOfRange_ConsoleBufferBoundaries); @@ -849,7 +849,7 @@ public static void SetBufferSize(int width, int height) size.Y = (short)height; if (!Interop.Kernel32.SetConsoleScreenBufferSize(OutputHandle, size)) { - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } } @@ -951,7 +951,7 @@ public static unsafe void SetWindowPosition(int left, int top) bool r = Interop.Kernel32.SetConsoleWindowInfo(OutputHandle, true, &srWindow); if (!r) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } public static unsafe void SetWindowSize(int width, int height) @@ -987,7 +987,7 @@ public static unsafe void SetWindowSize(int width, int height) if (resizeBuffer) { if (!Interop.Kernel32.SetConsoleScreenBufferSize(OutputHandle, size)) - throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); + throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastPInvokeError()); } Interop.Kernel32.SMALL_RECT srWindow = csbi.srWindow; @@ -997,7 +997,7 @@ public static unsafe void SetWindowSize(int width, int height) if (!Interop.Kernel32.SetConsoleWindowInfo(OutputHandle, true, &srWindow)) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); // If we resized the buffer, un-resize it. if (resizeBuffer) @@ -1070,7 +1070,7 @@ private static Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO GetBufferInfo(bool th !Interop.Kernel32.GetConsoleScreenBufferInfo(ErrorHandle, out csbi) && !Interop.Kernel32.GetConsoleScreenBufferInfo(InputHandle, out csbi)) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE && !throwOnNoConsole) return default; throw Win32Marshal.GetExceptionForWin32Error(errorCode); @@ -1178,7 +1178,7 @@ private static unsafe int ReadFileNative(IntPtr hFile, Span buffer, bool i // For pipes that are closing or broken, just stop. // (E.g. ERROR_NO_DATA ("pipe is being closed") is returned when we write to a console that is closing; // ERROR_BROKEN_PIPE ("pipe was closed") is returned when stdin was closed, which is not an error, but EOF.) - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_NO_DATA || errorCode == Interop.Errors.ERROR_BROKEN_PIPE) return Interop.Errors.ERROR_SUCCESS; return errorCode; @@ -1218,7 +1218,7 @@ private static unsafe int WriteFileNative(IntPtr hFile, ReadOnlySpan bytes // For pipes that are closing or broken, just stop. // (E.g. ERROR_NO_DATA ("pipe is being closed") is returned when we write to a console that is closing; // ERROR_BROKEN_PIPE ("pipe was closed") is returned when stdin was closed, which is not an error, but EOF.) - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode == Interop.Errors.ERROR_NO_DATA || errorCode == Interop.Errors.ERROR_BROKEN_PIPE) return Interop.Errors.ERROR_SUCCESS; return errorCode; diff --git a/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln b/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln index 40f2e6c07eb21..0982a373b5cef 100644 --- a/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln +++ b/src/libraries/System.IO.FileSystem.AccessControl/System.IO.FileSystem.AccessControl.sln @@ -41,9 +41,27 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{A9FD5D03-151 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices", "..\System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj", "{482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}" -EndProject Global + GlobalSection(NestedProjects) = preSolution + {18FD488A-2A3F-4B40-B65D-7108688D350F} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} + {9EB99AA1-EE31-41AC-B3E6-DCD7A01F17F2} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} + {BC0B86CC-54C1-450F-A710-13A66571EEBE} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {071FC282-9840-4920-B0FD-BE778449B5FF} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {C0B560B2-72A0-41B2-82D5-34EF31719AD7} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {D7E6A261-C80A-4E51-BCDD-85DD595866B9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {3709D2F4-5495-447A-81D1-D022B5A22DF9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {1AC0BFF9-2F4E-4E6A-8A5A-89DFF3AE2C74} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {37F8ED93-FD45-4941-B83E-84D278B8EA83} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {EAAF9D04-EB06-48C5-B678-662C777FBC7D} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {F33F1171-273A-4BC3-B138-25E5E7118186} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} + {4EF591E4-175E-494D-8191-15C2D6C6E2E6} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {35D57A83-8A9D-4531-BF0D-EA1BCA62D475} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {0EB6C67A-FD15-48A6-A608-F7E27DA8DB7E} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {62B4CB1C-16EE-4B2F-9FF1-DF2770A056F9} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {87E03C4D-FFE2-43AD-9CFE-BB67A2448186} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {4C5EE1EB-EACF-4A3A-88EC-CA7B3B7D50BA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -121,35 +139,10 @@ Global {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA}.Debug|Any CPU.Build.0 = Debug|Any CPU {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA}.Release|Any CPU.ActiveCfg = Release|Any CPU {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA}.Release|Any CPU.Build.0 = Release|Any CPU - {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {18FD488A-2A3F-4B40-B65D-7108688D350F} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} - {BC0B86CC-54C1-450F-A710-13A66571EEBE} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {071FC282-9840-4920-B0FD-BE778449B5FF} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {4EF591E4-175E-494D-8191-15C2D6C6E2E6} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {C0B560B2-72A0-41B2-82D5-34EF31719AD7} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {D7E6A261-C80A-4E51-BCDD-85DD595866B9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {35D57A83-8A9D-4531-BF0D-EA1BCA62D475} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {9EB99AA1-EE31-41AC-B3E6-DCD7A01F17F2} = {4C78F34A-DAF6-4298-A4D3-5C8FD380E33B} - {3709D2F4-5495-447A-81D1-D022B5A22DF9} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {0EB6C67A-FD15-48A6-A608-F7E27DA8DB7E} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {1AC0BFF9-2F4E-4E6A-8A5A-89DFF3AE2C74} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {62B4CB1C-16EE-4B2F-9FF1-DF2770A056F9} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {37F8ED93-FD45-4941-B83E-84D278B8EA83} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {87E03C4D-FFE2-43AD-9CFE-BB67A2448186} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {EAAF9D04-EB06-48C5-B678-662C777FBC7D} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {4C5EE1EB-EACF-4A3A-88EC-CA7B3B7D50BA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {F33F1171-273A-4BC3-B138-25E5E7118186} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - {83F2D6C4-C3C7-4428-A0CA-577162C5DBCA} = {2A945EB8-D29E-4FFA-A3AA-AF2D5EDAF6B1} - {482DE3DF-83A4-4B1B-BCDB-4E2D057FFB6E} = {A9FD5D03-1516-47D5-8CF4-FD9512E8CADB} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {246C2EDA-448E-4E76-B97A-BD93DC6883A7} EndGlobalSection diff --git a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj index 496aa1613ff3d..503971f5c7a22 100644 --- a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj +++ b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj @@ -1,4 +1,4 @@ - + $(NetCoreAppCurrent)-windows;netstandard2.0;netstandard2.0-windows;net461-windows true diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs index d361611377ed1..bb495b09c1310 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Windows.cs @@ -149,7 +149,7 @@ public unsafe string VolumeLabel bool r = Interop.Kernel32.SetVolumeLabel(Name, value); if (!r) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); // Provide better message if (errorCode == Interop.Errors.ERROR_ACCESS_DENIED) throw new UnauthorizedAccessException(SR.InvalidOperation_SetVolumeLabelFailed); diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/Error.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/Error.cs index 90998a89f81cf..bf8141073883e 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/Error.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/Error.cs @@ -13,7 +13,7 @@ internal static class Error // An alternative to Win32Marshal with friendlier messages for drives internal static Exception GetExceptionForLastWin32DriveError(string driveName) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); return GetExceptionForWin32DriveError(errorCode, driveName); } diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs index 2081e679cbc17..1bbc4648bf832 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs @@ -349,7 +349,7 @@ internal unsafe void Start(CancellationToken cancellationToken) if (!Interop.EventStream.FSEventStreamStart(_eventStream)) { // Try to get the Watcher to raise the error event; if we can't do that, just silently exit since the watcher is gone anyway - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); if (_weakWatcher.TryGetTarget(out FileSystemWatcher? watcher)) { // An error occurred while trying to start the run loop so fail out diff --git a/src/libraries/System.IO.FileSystem/tests/PortedCommon/IOServices.cs b/src/libraries/System.IO.FileSystem/tests/PortedCommon/IOServices.cs index 3fb3066d17f54..27b923dbd39c2 100644 --- a/src/libraries/System.IO.FileSystem/tests/PortedCommon/IOServices.cs +++ b/src/libraries/System.IO.FileSystem/tests/PortedCommon/IOServices.cs @@ -244,7 +244,7 @@ public static long GetAvailableFreeBytes(string drive) long userBytes; if (!DllImports.GetDiskFreeSpaceEx(drive, out userBytes, out ignored, out ignored)) { - throw new IOException("DriveName: " + drive + " ErrorCode:" + Marshal.GetLastWin32Error()); + throw new IOException("DriveName: " + drive + " ErrorCode:" + Marshal.GetLastPInvokeError()); } return userBytes; @@ -257,7 +257,7 @@ private static bool IsReady(string drive) long ignored; if (!DllImports.GetDiskFreeSpaceEx(drive, out ignored, out ignored, out ignored)) { - return Marshal.GetLastWin32Error() != ERROR_NOT_READY; + return Marshal.GetLastPInvokeError() != ERROR_NOT_READY; } return true; diff --git a/src/libraries/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs b/src/libraries/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs index d2304e1213fa0..5423bda6814b3 100644 --- a/src/libraries/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs +++ b/src/libraries/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs @@ -72,13 +72,13 @@ public static void Mount(string volumeName, string mountPoint) StringBuilder sb = new StringBuilder(1024); r = GetVolumeNameForVolumeMountPoint(volumeName, sb, sb.Capacity); if (!r) - throw new Exception(string.Format("Win32 error: {0}", Marshal.GetLastWin32Error())); + throw new Exception(string.Format("Win32 error: {0}", Marshal.GetLastPInvokeError())); string uniqueName = sb.ToString(); Console.WriteLine(string.Format("uniqueName: <{0}>", uniqueName)); r = SetVolumeMountPoint(mountPoint, uniqueName); if (!r) - throw new Exception(string.Format("Win32 error: {0}", Marshal.GetLastWin32Error())); + throw new Exception(string.Format("Win32 error: {0}", Marshal.GetLastPInvokeError())); Task.Delay(100).Wait(); // adding sleep for the file system to settle down so that reparse point mounting works } @@ -90,7 +90,7 @@ public static void Unmount(string mountPoint) bool r = DeleteVolumeMountPoint(mountPoint); if (!r) - throw new Exception(string.Format("Win32 error: {0}", Marshal.GetLastWin32Error())); + throw new Exception(string.Format("Win32 error: {0}", Marshal.GetLastPInvokeError())); } /// For standalone debugging help. Change Main0 to Main diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs index ad08669e8e008..8bc32eb666ef8 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs @@ -47,7 +47,7 @@ private static SafeMemoryMappedFileHandle CreateCore( Interop.CreateFileMapping(fileHandle, ref secAttrs, GetPageAccess(access) | (int)options, capacity, mapName) : Interop.CreateFileMapping(new IntPtr(-1), ref secAttrs, GetPageAccess(access) | (int)options, capacity, mapName); - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (!handle.IsInvalid) { if (errorCode == Interop.Errors.ERROR_ALREADY_EXISTS) @@ -126,7 +126,7 @@ private static SafeMemoryMappedFileHandle CreateOrOpenCore( else { handle.Dispose(); - int createErrorCode = Marshal.GetLastWin32Error(); + int createErrorCode = Marshal.GetLastPInvokeError(); if (createErrorCode != Interop.Errors.ERROR_ACCESS_DENIED) { throw Win32Marshal.GetExceptionForWin32Error(createErrorCode); @@ -146,7 +146,7 @@ private static SafeMemoryMappedFileHandle CreateOrOpenCore( else { handle.Dispose(); - int openErrorCode = Marshal.GetLastWin32Error(); + int openErrorCode = Marshal.GetLastPInvokeError(); if (openErrorCode != Interop.Errors.ERROR_FILE_NOT_FOUND) { throw Win32Marshal.GetExceptionForWin32Error(openErrorCode); diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs index cc3300c12c9fe..c47852bbb0140 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs @@ -62,7 +62,7 @@ public static MemoryMappedView CreateView(SafeMemoryMappedFileHandle memMappedFi IntPtr tempHandle = Interop.VirtualAlloc( viewHandle, (UIntPtr)(nativeSize != MemoryMappedFile.DefaultSize ? nativeSize : viewSize), Interop.Kernel32.MemOptions.MEM_COMMIT, MemoryMappedFile.GetPageAccess(access)); - int lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastPInvokeError(); if (viewHandle.IsInvalid) { viewHandle.Dispose(); @@ -110,7 +110,7 @@ public unsafe void Flush(UIntPtr capacity) // increasing intervals. Eventually, however, we need to give up. In ad-hoc tests // this strategy successfully flushed the view after no more than 3 retries. - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); if (error != Interop.Errors.ERROR_LOCK_VIOLATION) throw Win32Marshal.GetExceptionForWin32Error(error); @@ -125,7 +125,7 @@ public unsafe void Flush(UIntPtr capacity) if (Interop.Kernel32.FlushViewOfFile((IntPtr)firstPagePtr, capacity)) return; - error = Marshal.GetLastWin32Error(); + error = Marshal.GetLastPInvokeError(); if (error != Interop.Errors.ERROR_LOCK_VIOLATION) throw Win32Marshal.GetExceptionForWin32Error(error); diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.Windows.cs index a082a3da86397..51c1e58eea813 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.Windows.cs @@ -55,7 +55,7 @@ private bool TryConnect(int timeout, CancellationToken cancellationToken) if (handle.IsInvalid) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode != Interop.Errors.ERROR_PIPE_BUSY && errorCode != Interop.Errors.ERROR_FILE_NOT_FOUND) @@ -65,7 +65,7 @@ private bool TryConnect(int timeout, CancellationToken cancellationToken) if (!Interop.Kernel32.WaitNamedPipe(_normalizedPipePath, timeout)) { - errorCode = Marshal.GetLastWin32Error(); + errorCode = Marshal.GetLastPInvokeError(); // Server is not yet created or a timeout occurred before a pipe instance was available. if (errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND || @@ -88,7 +88,7 @@ private bool TryConnect(int timeout, CancellationToken cancellationToken) if (handle.IsInvalid) { - errorCode = Marshal.GetLastWin32Error(); + errorCode = Marshal.GetLastPInvokeError(); // Handle the possible race condition of someone else connecting to the server // between our calls to WaitNamedPipe & CreateFile. @@ -123,7 +123,7 @@ public unsafe int NumberOfServerInstances uint numInstances; if (!Interop.Kernel32.GetNamedPipeHandleStateW(InternalHandle!, null, &numInstances, null, null, null, 0)) { - throw WinIOError(Marshal.GetLastWin32Error()); + throw WinIOError(Marshal.GetLastPInvokeError()); } return (int)numInstances; diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Win32.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Win32.cs index 8039665ac0df5..172c44c3885a2 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Win32.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Win32.cs @@ -26,7 +26,7 @@ private unsafe string HandleGetImpersonationUserNameError(int error, uint userNa { return new string(userName); } - error = Marshal.GetLastWin32Error(); + error = Marshal.GetLastPInvokeError(); } throw WinIOError(error); diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs index a6ed15e1cd379..3abd2fed0451c 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs @@ -146,7 +146,7 @@ public void WaitForConnection() { if (!Interop.Kernel32.ConnectNamedPipe(InternalHandle!, IntPtr.Zero)) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); if (errorCode != Interop.Errors.ERROR_PIPE_CONNECTED) { @@ -211,7 +211,7 @@ public unsafe string GetImpersonationUserName() return new string(userName); } - return HandleGetImpersonationUserNameError(Marshal.GetLastWin32Error(), UserNameMaxLength, userName); + return HandleGetImpersonationUserNameError(Marshal.GetLastPInvokeError(), UserNameMaxLength, userName); } // This method calls a delegate while impersonating the client. Note that we will not have @@ -254,7 +254,7 @@ private static void ImpersonateAndTryCode(object? helper) } else { - execHelper._impersonateErrorCode = Marshal.GetLastWin32Error(); + execHelper._impersonateErrorCode = Marshal.GetLastPInvokeError(); } if (execHelper._mustRevert) @@ -272,7 +272,7 @@ private static void RevertImpersonationOnBackout(object? helper, bool exceptionT { if (!Interop.Advapi32.RevertToSelf()) { - execHelper._revertImpersonateErrorCode = Marshal.GetLastWin32Error(); + execHelper._revertImpersonateErrorCode = Marshal.GetLastPInvokeError(); } } } @@ -306,7 +306,7 @@ private unsafe Task WaitForConnectionCoreAsync(CancellationToken cancellationTok if (!Interop.Kernel32.ConnectNamedPipe(InternalHandle!, completionSource.Overlapped)) { - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); switch (errorCode) { diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeCompletionSource.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeCompletionSource.cs index 118463c35d0f7..39f47249a691e 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeCompletionSource.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeCompletionSource.cs @@ -147,7 +147,7 @@ private void Cancel() // This case should not have any consequences although // it will be easier to debug if there exists any special case // we are not aware of. - int errorCode = Marshal.GetLastWin32Error(); + int errorCode = Marshal.GetLastPInvokeError(); Debug.WriteLine("CancelIoEx finished with error code {0}.", errorCode); } } diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs index 928cc5d1a081f..d8c4bf2f8543d 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs @@ -403,7 +403,7 @@ public void WaitForPipeDrain() // Block until other end of the pipe has read everything. if (!Interop.Kernel32.FlushFileBuffers(_handle!)) { - throw WinIOError(Marshal.GetLastWin32Error()); + throw WinIOError(Marshal.GetLastPInvokeError()); } } @@ -420,7 +420,7 @@ public unsafe virtual PipeTransmissionMode TransmissionMode uint pipeFlags; if (!Interop.Kernel32.GetNamedPipeInfo(_handle!, &pipeFlags, null, null, null)) { - throw WinIOError(Marshal.GetLastWin32Error()); + throw WinIOError(Marshal.GetLastPInvokeError()); } if ((pipeFlags & Interop.Kernel32.PipeOptions.PIPE_TYPE_MESSAGE) != 0) { @@ -453,7 +453,7 @@ public unsafe virtual int InBufferSize uint inBufferSize; if (!Interop.Kernel32.GetNamedPipeInfo(_handle!, null, null, &inBufferSize, null)) { - throw WinIOError(Marshal.GetLastWin32Error()); + throw WinIOError(Marshal.GetLastPInvokeError()); } return (int)inBufferSize; @@ -483,7 +483,7 @@ public unsafe virtual int OutBufferSize } else if (!Interop.Kernel32.GetNamedPipeInfo(_handle!, null, &outBufferSize, null, null)) { - throw WinIOError(Marshal.GetLastWin32Error()); + throw WinIOError(Marshal.GetLastPInvokeError()); } return (int)outBufferSize; @@ -519,7 +519,7 @@ public virtual PipeTransmissionMode ReadMode int pipeReadType = (int)value << 1; if (!Interop.Kernel32.SetNamedPipeHandleState(_handle!, &pipeReadType, IntPtr.Zero, IntPtr.Zero)) { - throw WinIOError(Marshal.GetLastWin32Error()); + throw WinIOError(Marshal.GetLastPInvokeError()); } else { @@ -554,7 +554,7 @@ private unsafe int ReadFileNative(SafePipeHandle handle, Span buffer, Nati if (r == 0) { // In message mode, the ReadFile can inform us that there is more data to come. - errorCode = Marshal.GetLastWin32Error(); + errorCode = Marshal.GetLastPInvokeError(); return errorCode == Interop.Errors.ERROR_MORE_DATA ? numBytesRead : -1; @@ -590,7 +590,7 @@ private unsafe int WriteFileNative(SafePipeHandle handle, ReadOnlySpan buf if (r == 0) { - errorCode = Marshal.GetLastWin32Error(); + errorCode = Marshal.GetLastPInvokeError(); return -1; } else @@ -638,7 +638,7 @@ private unsafe void UpdateReadMode() uint flags; if (!Interop.Kernel32.GetNamedPipeHandleStateW(SafePipeHandle, &flags, null, null, null, null, 0)) { - throw WinIOError(Marshal.GetLastWin32Error()); + throw WinIOError(Marshal.GetLastPInvokeError()); } if ((flags & Interop.Kernel32.PipeOptions.PIPE_READMODE_MESSAGE) != 0) diff --git a/src/libraries/System.IO.Pipes/tests/InteropTest.Windows.cs b/src/libraries/System.IO.Pipes/tests/InteropTest.Windows.cs index 087237e2352c6..ce6065d679574 100644 --- a/src/libraries/System.IO.Pipes/tests/InteropTest.Windows.cs +++ b/src/libraries/System.IO.Pipes/tests/InteropTest.Windows.cs @@ -27,7 +27,7 @@ internal static unsafe bool TryGetImpersonationUserName(SafePipeHandle handle, o return true; } - return TryHandleGetImpersonationUserNameError(handle, Marshal.GetLastWin32Error(), UserNameMaxLength, userName, out impersonationUserName); + return TryHandleGetImpersonationUserNameError(handle, Marshal.GetLastPInvokeError(), UserNameMaxLength, userName, out impersonationUserName); } internal static unsafe bool TryGetNumberOfServerInstances(SafePipeHandle handle, out uint numberOfServerInstances) diff --git a/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln b/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln index 223a6b42197bf..f9b2b579d78fd 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln +++ b/src/libraries/System.Net.Http.WinHttpHandler/System.Net.Http.WinHttpHandler.sln @@ -42,6 +42,26 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2E71EAE8-4677-4E28-A2A3-09AD42E702EC}" EndProject Global + GlobalSection(NestedProjects) = preSolution + {49FC63FA-3E81-4335-91CF-B5056E007343} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} + {E9D5AB56-2597-42E0-BE81-C00CC63D1FB3} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} + {090BA6CA-F661-4BDE-9663-65F8231DDB1D} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} + {D18082CB-C337-473B-8AC3-5FCC312F90C6} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {845F6CBC-8663-446C-B874-9BE54D2EF6EC} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {6FD15E9F-9E3B-494C-8F7F-67C9641A3FDB} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {B3C3E9D6-EEB3-4DE1-9B35-C0984474E522} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {E2311DD8-2E5E-4DD7-840F-237A8F77A311} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {B294FD03-AC49-4235-863F-5966BAB0C84D} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {6408B084-5213-4955-8262-6740B96045B2} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} + {4BA25EC1-B76B-4410-AF2D-A54B90FAB404} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {7EF13CC5-C714-4C0F-990F-C0884B92A9A1} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {E6A8B90B-69CD-4B0D-8A33-F208A3169674} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {DE2A69CC-4962-4BF6-A714-41A87A6C045B} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {28C24BF8-8E08-485F-8EEE-817EB847774C} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {488643D8-1F81-4998-8A6C-E00978977AD2} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {BACC5257-6CA8-45C7-970F-C8D501DA59AB} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + {E470810A-BAF2-4B3C-92CB-72007B7F1B6A} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -123,26 +143,6 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {49FC63FA-3E81-4335-91CF-B5056E007343} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} - {D18082CB-C337-473B-8AC3-5FCC312F90C6} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {4BA25EC1-B76B-4410-AF2D-A54B90FAB404} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {845F6CBC-8663-446C-B874-9BE54D2EF6EC} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {6FD15E9F-9E3B-494C-8F7F-67C9641A3FDB} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {7EF13CC5-C714-4C0F-990F-C0884B92A9A1} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {E6A8B90B-69CD-4B0D-8A33-F208A3169674} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {B3C3E9D6-EEB3-4DE1-9B35-C0984474E522} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {DE2A69CC-4962-4BF6-A714-41A87A6C045B} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {E9D5AB56-2597-42E0-BE81-C00CC63D1FB3} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} - {090BA6CA-F661-4BDE-9663-65F8231DDB1D} = {D26A4951-218E-4AC9-BDA0-AB7E654E1472} - {E2311DD8-2E5E-4DD7-840F-237A8F77A311} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {28C24BF8-8E08-485F-8EEE-817EB847774C} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {B294FD03-AC49-4235-863F-5966BAB0C84D} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {6408B084-5213-4955-8262-6740B96045B2} = {80770A49-D1DC-4FB3-9C3E-3DE94ED72B62} - {488643D8-1F81-4998-8A6C-E00978977AD2} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {BACC5257-6CA8-45C7-970F-C8D501DA59AB} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - {E470810A-BAF2-4B3C-92CB-72007B7F1B6A} = {2E71EAE8-4677-4E28-A2A3-09AD42E702EC} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F5BAF3DD-D05C-4DCC-BB36-16645CA1F151} EndGlobalSection diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj index 4329efc36955b..3a1719f2c0d6c 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj @@ -1,4 +1,4 @@ - + true netstandard2.0-windows;netstandard2.0;netstandard2.1-windows;netstandard2.1;net461-windows diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerException.cs b/src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerException.cs index 62d3751da7482..968adb53345d0 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerException.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerException.cs @@ -11,7 +11,7 @@ namespace System.Net [System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class HttpListenerException : Win32Exception { - public HttpListenerException() : base(Marshal.GetLastWin32Error()) + public HttpListenerException() : base(Marshal.GetLastPInvokeError()) { if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, NativeErrorCode.ToString() + ":" + Message); } diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerSession.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerSession.Windows.cs index 777335be91a98..5c681b745a2f3 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerSession.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerSession.Windows.cs @@ -52,7 +52,7 @@ public unsafe HttpListenerSession(HttpListener listener) Interop.Kernel32.FileCompletionNotificationModes.SkipCompletionPortOnSuccess | Interop.Kernel32.FileCompletionNotificationModes.SkipSetEventOnHandle)) { - throw new HttpListenerException(Marshal.GetLastWin32Error()); + throw new HttpListenerException(Marshal.GetLastPInvokeError()); } RequestQueueHandle = requestQueueHandle; diff --git a/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Windows.cs b/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Windows.cs index 3ded687bcf4a3..574d5577a2ccc 100644 --- a/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Windows.cs +++ b/src/libraries/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Windows.cs @@ -82,7 +82,7 @@ private Task DoSendPingCore(IPAddress address, byte[] buffer, int tim if (error == 0) { - error = Marshal.GetLastWin32Error(); + error = Marshal.GetLastPInvokeError(); // Only skip Async IO Pending error value. if (!isAsync || error != Interop.IpHlpApi.ERROR_IO_PENDING) diff --git a/src/libraries/System.Net.Primitives/src/System/Net/SocketException.Windows.cs b/src/libraries/System.Net.Primitives/src/System/Net/SocketException.Windows.cs index 6d81c8ef97fe6..8952b76109403 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/SocketException.Windows.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/SocketException.Windows.cs @@ -9,7 +9,7 @@ namespace System.Net.Sockets public partial class SocketException : Win32Exception { /// Creates a new instance of the class with the default error code. - public SocketException() : this(Marshal.GetLastWin32Error()) + public SocketException() : this(Marshal.GetLastPInvokeError()) { } diff --git a/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs b/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs index 093cd0719dd09..ca9494b3b023b 100644 --- a/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs +++ b/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs @@ -27,7 +27,7 @@ internal static SslPolicyErrors VerifyCertificateProperties( if (!chainBuildResult // Build failed on handle or on policy. && chain.SafeHandle!.DangerousGetHandle() == IntPtr.Zero) // Build failed to generate a valid handle. { - throw new CryptographicException(Marshal.GetLastWin32Error()); + throw new CryptographicException(Marshal.GetLastPInvokeError()); } if (checkCertName) diff --git a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocketException.cs b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocketException.cs index b2e2235641060..d21721fc25420 100644 --- a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocketException.cs +++ b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocketException.cs @@ -15,7 +15,7 @@ public sealed class WebSocketException : Win32Exception private readonly WebSocketError _webSocketErrorCode; public WebSocketException() - : this(Marshal.GetLastWin32Error()) + : this(Marshal.GetLastPInvokeError()) { } diff --git a/src/libraries/System.Net.WebSockets/tests/WebSocketExceptionTests.cs b/src/libraries/System.Net.WebSockets/tests/WebSocketExceptionTests.cs index 83204359bfd62..0d5e4d90490c1 100644 --- a/src/libraries/System.Net.WebSockets/tests/WebSocketExceptionTests.cs +++ b/src/libraries/System.Net.WebSockets/tests/WebSocketExceptionTests.cs @@ -34,7 +34,7 @@ public sealed partial class WebSocketExceptionTests [Fact] public void ConstructorTests_Parameterless_Success() { - int lastError = Marshal.GetLastWin32Error(); + int lastError = Marshal.GetLastPInvokeError(); var wse = new WebSocketException(); Assert.Equal(wse.NativeErrorCode, lastError); Assert.Equal(wse.ErrorCode, lastError); diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs index c51ea851d823b..377cde1305d74 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs @@ -83,11 +83,7 @@ private static void GetFullPathName(ReadOnlySpan path, ref ValueStringBuil if (result == 0) { // Failure, get the error and throw -#if NET6_0 - int errorCode = Marshal.GetLastPInvokeError(); -#else int errorCode = Marshal.GetLastWin32Error(); -#endif if (errorCode == 0) errorCode = Interop.Errors.ERROR_BAD_PATHNAME; throw Win32Marshal.GetExceptionForWin32Error(errorCode, path.ToString()); @@ -189,11 +185,7 @@ internal static string TryExpandShortFileName(ref ValueStringBuilder outputBuild if (result == 0) { // Look to see if we couldn't find the file -#if NET6_0 - int error = Marshal.GetLastPInvokeError(); -#else int error = Marshal.GetLastWin32Error(); -#endif if (error != Interop.Errors.ERROR_FILE_NOT_FOUND && error != Interop.Errors.ERROR_PATH_NOT_FOUND) { // Some other failure, give up diff --git a/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs index 8415493fbf0e1..f027d6859a817 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs @@ -475,7 +475,7 @@ private void AssertDirectoryExists(string path) FileAttributes attributes = GetFileAttributesW(path); if (attributes == (FileAttributes)(-1)) { - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); Assert.False(true, $"error {error} getting attributes for {path}"); } diff --git a/src/libraries/System.Runtime.Handles/tests/SafeHandle.cs b/src/libraries/System.Runtime.Handles/tests/SafeHandle.cs index 4c663184d4d64..80d38992e6d66 100644 --- a/src/libraries/System.Runtime.Handles/tests/SafeHandle.cs +++ b/src/libraries/System.Runtime.Handles/tests/SafeHandle.cs @@ -113,7 +113,7 @@ public static void SafeHandle_DangerousReleasePreservesLastError() SetLastError(42); handle.DangerousRelease(); - int error = Marshal.GetLastWin32Error(); + int error = Marshal.GetLastPInvokeError(); Assert.Equal(42, error); } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs index e16110f1a07a4..99a6b0b543898 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs @@ -28,7 +28,7 @@ public void SetLastPInvokeError_GetLastWin32Error() { int errorExpected = 123; Marshal.SetLastPInvokeError(errorExpected); - Assert.Equal(errorExpected, Marshal.GetLastWin32Error()); + Assert.Equal(errorExpected, Marshal.GetLastPInvokeError()); } [Fact] @@ -45,7 +45,7 @@ public void SetLastSystemError_PInvokeErrorUnchanged() Assert.NotEqual(systemError, pinvokeActual); Assert.Equal(pinvokeError, pinvokeActual); - int win32Actual = Marshal.GetLastWin32Error(); + int win32Actual = Marshal.GetLastPInvokeError(); Assert.NotEqual(systemError, win32Actual); Assert.Equal(pinvokeError, win32Actual); } diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs index 913d8397e9f3a..c78a1721c72a3 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs @@ -768,7 +768,7 @@ internal static SafeKeyHandle GetKeyPairHelper( /// returns the error code internal static int GetErrorCode() { - return Marshal.GetLastWin32Error(); + return Marshal.GetLastPInvokeError(); } /// diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln b/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln index 0be65f24b8c9a..f405d1179d45d 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln +++ b/src/libraries/System.Security.Cryptography.ProtectedData/System.Security.Cryptography.ProtectedData.sln @@ -23,9 +23,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{E71CB63B-6EB EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{60F975CB-2CC9-43E1-804B-9FB4142F49E8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.InteropServices", "..\System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj", "{C9FBEDE9-6A21-4696-8259-79C0B885BB79}" -EndProject Global + GlobalSection(NestedProjects) = preSolution + {21CC9F35-ACAA-4452-BE92-BBAE2E927B20} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} + {3A6C62D5-EFCA-4119-BC60-C917533848A8} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} + {4248C69F-DFF2-4E47-9749-E12D1312F5D5} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {179902DA-28E6-42F5-BA2D-905BEC68A32C} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {C25543F0-E445-45AF-809D-388DF6496520} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {E40DBC0E-386A-4B32-8DCE-9FE13EAD47BE} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {B3C3180D-31E8-4225-8A5D-6765945C9647} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} + {90042C2E-6AD9-4BFF-B7CA-8E6BF9B3D3C7} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} + {7773DB7A-494F-4508-9471-F737FDC7661E} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -67,26 +76,10 @@ Global {B3C3180D-31E8-4225-8A5D-6765945C9647}.Debug|Any CPU.Build.0 = Debug|Any CPU {B3C3180D-31E8-4225-8A5D-6765945C9647}.Release|Any CPU.ActiveCfg = Release|Any CPU {B3C3180D-31E8-4225-8A5D-6765945C9647}.Release|Any CPU.Build.0 = Release|Any CPU - {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C9FBEDE9-6A21-4696-8259-79C0B885BB79}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {21CC9F35-ACAA-4452-BE92-BBAE2E927B20} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} - {4248C69F-DFF2-4E47-9749-E12D1312F5D5} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {179902DA-28E6-42F5-BA2D-905BEC68A32C} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {90042C2E-6AD9-4BFF-B7CA-8E6BF9B3D3C7} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} - {C25543F0-E445-45AF-809D-388DF6496520} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {E40DBC0E-386A-4B32-8DCE-9FE13EAD47BE} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {7773DB7A-494F-4508-9471-F737FDC7661E} = {60F975CB-2CC9-43E1-804B-9FB4142F49E8} - {3A6C62D5-EFCA-4119-BC60-C917533848A8} = {4BF33DE6-1FFA-4CC3-92DA-02A6931B89FD} - {B3C3180D-31E8-4225-8A5D-6765945C9647} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - {C9FBEDE9-6A21-4696-8259-79C0B885BB79} = {E71CB63B-6EB0-473D-A2AE-487B7B280AB1} - EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FB101479-5EAB-495B-ACF3-4B6FC3F830EF} EndGlobalSection diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj index 946ac31b8ace4..58751f8256471 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj +++ b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj @@ -1,7 +1,7 @@ true - $(NetCoreAppCurrent);netstandard2.0-windows;net461-windows;netstandard2.0 + netstandard2.0-windows;net461-windows;netstandard2.0 enable @@ -39,7 +39,4 @@ - - - - + \ No newline at end of file diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs b/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs index 4dfb1d9305b68..0e6b65bea1664 100644 --- a/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs +++ b/src/libraries/System.Security.Cryptography.ProtectedData/src/System/Security/Cryptography/ProtectedData.cs @@ -63,11 +63,7 @@ private static byte[] ProtectOrUnprotect(byte[] inputData, byte[]? optionalEntro Interop.Crypt32.CryptUnprotectData(ref userDataBlob, IntPtr.Zero, ref optionalEntropyBlob, IntPtr.Zero, IntPtr.Zero, flags, out outputBlob); if (!success) { -#if NET6_0 - int lastWin32Error = Marshal.GetLastPInvokeError(); -#else int lastWin32Error = Marshal.GetLastWin32Error(); -#endif if (protect && ErrorMayBeCausedByUnloadedProfile(lastWin32Error)) throw new CryptographicException(SR.Cryptography_DpApi_ProfileMayNotBeLoaded); else diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index 5d2d1eefbda6b..da3e843491517 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -1,4 +1,4 @@ - + true $(NetCoreAppCurrent);netstandard2.0;netcoreapp3.0;net461 diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs index 85daba2b48e5a..008bf7aa2a571 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs @@ -32,7 +32,7 @@ public unsafe void SingleOperationOverSingleHandle() if (retval == 0) { - Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error()); + Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastPInvokeError()); } // Wait for overlapped operation to complete @@ -77,7 +77,7 @@ public unsafe void MultipleOperationsOverSingleHandle() if (retval == 0) { - Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error()); + Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastPInvokeError()); } @@ -87,7 +87,7 @@ public unsafe void MultipleOperationsOverSingleHandle() if (retval == 0) { - Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error()); + Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastPInvokeError()); } // Wait for overlapped operations to complete @@ -142,7 +142,7 @@ public unsafe void MultipleOperationsOverMultipleHandles() if (retval == 0) { - Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error()); + Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastPInvokeError()); } @@ -150,7 +150,7 @@ public unsafe void MultipleOperationsOverMultipleHandles() if (retval == 0) { - Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error()); + Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastPInvokeError()); } // Wait for overlapped operations to complete @@ -209,7 +209,7 @@ public unsafe void FlowsAsyncLocalsToCallback() if (retval == 0) { - Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastWin32Error()); + Assert.Equal(DllImport.ERROR_IO_PENDING, Marshal.GetLastPInvokeError()); } // Wait for overlapped operation to complete From b511c10292208c566889409fa14e23fa48b87ed5 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 9 May 2021 07:12:14 -0700 Subject: [PATCH 6/6] Apply suggestions from code review --- .../System/Runtime/InteropServices/Marshal/LastErrorTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs index 99a6b0b543898..e16110f1a07a4 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/LastErrorTests.cs @@ -28,7 +28,7 @@ public void SetLastPInvokeError_GetLastWin32Error() { int errorExpected = 123; Marshal.SetLastPInvokeError(errorExpected); - Assert.Equal(errorExpected, Marshal.GetLastPInvokeError()); + Assert.Equal(errorExpected, Marshal.GetLastWin32Error()); } [Fact] @@ -45,7 +45,7 @@ public void SetLastSystemError_PInvokeErrorUnchanged() Assert.NotEqual(systemError, pinvokeActual); Assert.Equal(pinvokeError, pinvokeActual); - int win32Actual = Marshal.GetLastPInvokeError(); + int win32Actual = Marshal.GetLastWin32Error(); Assert.NotEqual(systemError, win32Actual); Assert.Equal(pinvokeError, win32Actual); }