diff --git a/.globalconfig b/.globalconfig
index 32bea9725fd..4590b0704f8 100644
--- a/.globalconfig
+++ b/.globalconfig
@@ -266,7 +266,7 @@ dotnet_diagnostic.CA1814.severity = none
dotnet_diagnostic.CA1815.severity = none
# CA1816: Dispose methods should call SuppressFinalize
-dotnet_diagnostic.CA1816.severity = suggestion
+dotnet_diagnostic.CA1816.severity = warning
# CA1819: Properties should not return arrays
dotnet_diagnostic.CA1819.severity = none
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs
index 023fc1d0501..23894ed9f63 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/ComputerUnix.cs
@@ -101,11 +101,28 @@ public class CommandLineCmdletBase : PSCmdlet, IDisposable
#region "IDisposable Members"
///
- /// Dispose Method.
+ /// Releases all resources used by the .
///
public void Dispose()
{
- _process?.Dispose();
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// Releases the unmanaged resources used by the
+ /// and optionally releases the managed resources.
+ ///
+ ///
+ /// to release both managed and unmanaged resources;
+ /// to release only unmanaged resources.
+ ///
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ _process?.Dispose();
+ }
}
#endregion "IDisposable Members"
diff --git a/test/xUnit/csharp/test_FileSystemProvider.cs b/test/xUnit/csharp/test_FileSystemProvider.cs
index ef702d47bd6..23702755e77 100644
--- a/test/xUnit/csharp/test_FileSystemProvider.cs
+++ b/test/xUnit/csharp/test_FileSystemProvider.cs
@@ -39,9 +39,18 @@ public FileSystemProviderTests()
File.AppendAllText(testPath, testContent);
}
- void IDisposable.Dispose()
+ public void Dispose()
{
- File.Delete(testPath);
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ File.Delete(testPath);
+ }
}
private ExecutionContext GetExecutionContext()
diff --git a/test/xUnit/csharp/test_PSConfiguration.cs b/test/xUnit/csharp/test_PSConfiguration.cs
index 6237f453335..ef1cf21715d 100644
--- a/test/xUnit/csharp/test_PSConfiguration.cs
+++ b/test/xUnit/csharp/test_PSConfiguration.cs
@@ -97,18 +97,27 @@ public PowerShellPolicyFixture()
public void Dispose()
{
- CleanupConfigFiles();
- if (systemWideConfigBackupFile != null)
- {
- File.Move(systemWideConfigBackupFile, systemWideConfigFile);
- }
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
- if (currentUserConfigBackupFile != null)
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
{
- File.Move(currentUserConfigBackupFile, currentUserConfigFile);
- }
+ CleanupConfigFiles();
+ if (systemWideConfigBackupFile != null)
+ {
+ File.Move(systemWideConfigBackupFile, systemWideConfigFile);
+ }
- InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
+ if (currentUserConfigBackupFile != null)
+ {
+ File.Move(currentUserConfigBackupFile, currentUserConfigFile);
+ }
+
+ InternalTestHooks.BypassGroupPolicyCaching = originalTestHookValue;
+ }
}
internal PowerShellPolicies SystemWidePolicies