diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs index 014eb6db922..fa23e31a473 100644 --- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs +++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs @@ -3088,7 +3088,7 @@ public static void WriteSendAsTrustedIssuerProperty(X509Certificate2 cert, strin } else { - throw Marshal.GetExceptionForHR(Security.NativeMethods.NTE_NOT_SUPPORTED); + Marshal.ThrowExceptionForHR(Security.NativeMethods.NTE_NOT_SUPPORTED); } } diff --git a/src/System.Management.Automation/engine/parser/FusionAssemblyIdentity.cs b/src/System.Management.Automation/engine/parser/FusionAssemblyIdentity.cs index 8eebb804dd1..6970e17b7cd 100644 --- a/src/System.Management.Automation/engine/parser/FusionAssemblyIdentity.cs +++ b/src/System.Management.Automation/engine/parser/FusionAssemblyIdentity.cs @@ -133,17 +133,14 @@ internal static unsafe string GetDisplayName(IAssemblyName nameObject, ASM_DISPL if (hr != ERROR_INSUFFICIENT_BUFFER) { - throw Marshal.GetExceptionForHR(hr); + Marshal.ThrowExceptionForHR(hr); } byte[] data = new byte[(int)characterCountIncludingTerminator * 2]; fixed (byte* p = data) { hr = nameObject.GetDisplayName(p, ref characterCountIncludingTerminator, displayFlags); - if (hr != 0) - { - throw Marshal.GetExceptionForHR(hr); - } + Marshal.ThrowExceptionForHR(hr); return Marshal.PtrToStringUni((IntPtr)p, (int)characterCountIncludingTerminator - 1); } @@ -162,17 +159,14 @@ internal static unsafe byte[] GetPropertyBytes(IAssemblyName nameObject, Propert if (hr != ERROR_INSUFFICIENT_BUFFER) { - throw Marshal.GetExceptionForHR(hr); + Marshal.ThrowExceptionForHR(hr); } byte[] data = new byte[(int)size]; fixed (byte* p = data) { hr = nameObject.GetProperty(propertyId, p, ref size); - if (hr != 0) - { - throw Marshal.GetExceptionForHR(hr); - } + Marshal.ThrowExceptionForHR(hr); } return data; @@ -210,10 +204,7 @@ internal static unsafe Version GetVersion(IAssemblyName nameObject) uint result; uint size = sizeof(uint); int hr = nameObject.GetProperty(propertyId, &result, ref size); - if (hr != 0) - { - throw Marshal.GetExceptionForHR(hr); - } + Marshal.ThrowExceptionForHR(hr); if (size == 0) { diff --git a/src/System.Management.Automation/security/SecuritySupport.cs b/src/System.Management.Automation/security/SecuritySupport.cs index 41c92c01915..ee1058be350 100644 --- a/src/System.Management.Automation/security/SecuritySupport.cs +++ b/src/System.Management.Automation/security/SecuritySupport.cs @@ -900,8 +900,7 @@ private string AppendFilter( if (newfilter.Contains("=") || newfilter.Contains("&")) { - throw Marshal.GetExceptionForHR( - Security.NativeMethods.E_INVALID_DATA); + Marshal.ThrowExceptionForHR(Security.NativeMethods.E_INVALID_DATA); } newfilter = name + "=" + newfilter;