From 093916caae070930a0351e2b5fb122eb454ce503 Mon Sep 17 00:00:00 2001 From: dahall Date: Thu, 10 Mar 2022 17:44:40 -0700 Subject: [PATCH] Fixed bug in Win32Error.ThrowLastErrorIf method that would exception if error was success. --- PInvoke/Shared/WinError/Win32Error.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PInvoke/Shared/WinError/Win32Error.cs b/PInvoke/Shared/WinError/Win32Error.cs index 1f717155..3967c53f 100644 --- a/PInvoke/Shared/WinError/Win32Error.cs +++ b/PInvoke/Shared/WinError/Win32Error.cs @@ -104,8 +104,12 @@ namespace Vanara.PInvoke /// The delegate which returns on failure. /// The message. /// The passed in on success. - public static T ThrowLastErrorIf(T value, Func valueIsFailure, string message = null) => - !valueIsFailure(value) ? value : throw GetLastError().GetException(message); + public static T ThrowLastErrorIf(T value, Func valueIsFailure, string message = null) + { + if (valueIsFailure(value)) + GetLastError().ThrowIfFailed(message); + return value; + } /// Throws the last error if the function returns . /// The value to check.