diff options
author | Jordan Borean <jborean93@gmail.com> | 2023-09-01 05:10:17 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 14:10:17 -0500 |
commit | 7d48bef252d19e3e9c59ba4647d4bb5507e4022c (patch) | |
tree | fac9eecce5b0bdbb2a905ba0a0281da2f27a63d7 | |
parent | e7f64ed9d5da541c265c17b13df65a21884d9815 (diff) | |
download | ansible-7d48bef252d19e3e9c59ba4647d4bb5507e4022c.zip |
PowerShell - remove uneeded dotnet code for future compatibility (#81472) (#81576)
(cherry picked from commit f3976117fb109f31401271af4c60b740368ac3c8)
7 files changed, 3 insertions, 19 deletions
diff --git a/changelogs/fragments/dotnet-preparation.yml b/changelogs/fragments/dotnet-preparation.yml new file mode 100644 index 0000000000..208d1c28d2 --- /dev/null +++ b/changelogs/fragments/dotnet-preparation.yml @@ -0,0 +1,2 @@ +bugfixes: +- PowerShell - Remove some code which is no longer valid for dotnet 5+ diff --git a/lib/ansible/module_utils/csharp/Ansible.AccessToken.cs b/lib/ansible/module_utils/csharp/Ansible.AccessToken.cs index 48c4a197ae..49fba4e5e7 100644 --- a/lib/ansible/module_utils/csharp/Ansible.AccessToken.cs +++ b/lib/ansible/module_utils/csharp/Ansible.AccessToken.cs @@ -2,7 +2,6 @@ using Microsoft.Win32.SafeHandles; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security.Principal; using System.Text; @@ -123,7 +122,6 @@ namespace Ansible.AccessToken base.SetHandle(handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); @@ -247,7 +245,6 @@ namespace Ansible.AccessToken public SafeNativeHandle() : base(true) { } public SafeNativeHandle(IntPtr handle) : base(true) { this.handle = handle; } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { return NativeMethods.CloseHandle(handle); diff --git a/lib/ansible/module_utils/csharp/Ansible.Become.cs b/lib/ansible/module_utils/csharp/Ansible.Become.cs index a6f645cabd..d3bb1564fa 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Become.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Become.cs @@ -4,7 +4,6 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security.AccessControl; using System.Security.Principal; @@ -175,7 +174,6 @@ namespace Ansible.Become { public SafeLsaHandle() : base(true) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { UInt32 res = NativeMethods.LsaDeregisterLogonProcess(handle); @@ -187,7 +185,6 @@ namespace Ansible.Become { public SafeLsaMemoryBuffer() : base(true) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { UInt32 res = NativeMethods.LsaFreeReturnBuffer(handle); @@ -200,7 +197,6 @@ namespace Ansible.Become public NoopSafeHandle() : base(IntPtr.Zero, false) { } public override bool IsInvalid { get { return false; } } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { return true; } } diff --git a/lib/ansible/module_utils/csharp/Ansible.Privilege.cs b/lib/ansible/module_utils/csharp/Ansible.Privilege.cs index 2c0b266bf7..9d5c0b1719 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Privilege.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Privilege.cs @@ -3,7 +3,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security.Principal; using System.Text; @@ -92,7 +91,6 @@ namespace Ansible.Privilege { base.SetHandle(handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); @@ -104,7 +102,7 @@ namespace Ansible.Privilege { public SafeNativeHandle() : base(true) { } public SafeNativeHandle(IntPtr handle) : base(true) { this.handle = handle; } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] + protected override bool ReleaseHandle() { return NativeMethods.CloseHandle(handle); diff --git a/lib/ansible/module_utils/csharp/Ansible.Process.cs b/lib/ansible/module_utils/csharp/Ansible.Process.cs index f4c68f0529..fc156b7a20 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Process.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Process.cs @@ -3,7 +3,6 @@ using System; using System.Collections; using System.IO; using System.Linq; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -176,7 +175,6 @@ namespace Ansible.Process base.SetHandle(handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); diff --git a/test/integration/targets/module_utils_Ansible.Become/library/ansible_become_tests.ps1 b/test/integration/targets/module_utils_Ansible.Become/library/ansible_become_tests.ps1 index 6e36321154..163d035a77 100644 --- a/test/integration/targets/module_utils_Ansible.Become/library/ansible_become_tests.ps1 +++ b/test/integration/targets/module_utils_Ansible.Become/library/ansible_become_tests.ps1 @@ -48,7 +48,6 @@ $test_whoami = { Add-Type -TypeDefinition @' using Microsoft.Win32.SafeHandles; using System; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security.Principal; using System.Text; @@ -212,7 +211,6 @@ namespace Ansible { public SafeLsaMemoryBuffer() : base(true) { } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { UInt32 res = NativeMethods.LsaFreeReturnBuffer(handle); @@ -232,7 +230,6 @@ namespace Ansible base.SetHandle(handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); @@ -245,7 +242,6 @@ namespace Ansible public SafeNativeHandle() : base(true) { } public SafeNativeHandle(IntPtr handle) : base(true) { this.handle = handle; } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { return NativeMethods.CloseHandle(handle); diff --git a/test/support/windows-integration/plugins/module_utils/Ansible.Service.cs b/test/support/windows-integration/plugins/module_utils/Ansible.Service.cs index be0f3db3f3..4b963a9dc3 100644 --- a/test/support/windows-integration/plugins/module_utils/Ansible.Service.cs +++ b/test/support/windows-integration/plugins/module_utils/Ansible.Service.cs @@ -2,7 +2,6 @@ using Microsoft.Win32.SafeHandles; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security.Principal; using System.Text; @@ -274,7 +273,6 @@ namespace Ansible.Service base.SetHandle(handle); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); @@ -287,7 +285,6 @@ namespace Ansible.Service public SafeServiceHandle() : base(true) { } public SafeServiceHandle(IntPtr handle) : base(true) { this.handle = handle; } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected override bool ReleaseHandle() { return NativeMethods.CloseServiceHandle(handle); |