diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs
index 059f58a97b2..a7e75bb98c7 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs
@@ -672,6 +672,7 @@ internal virtual CmdletOperationBase CmdletOperation
/// Throw terminating error
///
///
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
internal void ThrowTerminatingError(Exception exception, string operation)
{
ErrorRecord errorRecord = new(exception, operation, ErrorCategory.InvalidOperation, this);
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
index 3c49b1dcbb8..03db6967aef 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CmdletOperation.cs
@@ -65,6 +65,7 @@ public virtual bool ShouldProcess(string verboseDescription, string verboseWarni
return cmdlet.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason);
}
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
public virtual void ThrowTerminatingError(ErrorRecord errorRecord)
{
cmdlet.ThrowTerminatingError(errorRecord);
@@ -115,6 +116,7 @@ public virtual void WriteWarning(string text)
/// Throw terminating error
///
///
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
internal void ThrowTerminatingError(Exception exception, string operation)
{
ErrorRecord errorRecord = new(exception, operation, ErrorCategory.InvalidOperation, this);
diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs
index dcfb79d4aed..e59cae40146 100644
--- a/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs
+++ b/src/System.Management.Automation/FormatAndOutput/common/BaseCommand.cs
@@ -22,6 +22,7 @@ internal TerminatingErrorContext(PSCmdlet command)
_command = command;
}
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
internal void ThrowTerminatingError(ErrorRecord errorRecord)
{
_command.ThrowTerminatingError(errorRecord);
diff --git a/src/System.Management.Automation/engine/DefaultCommandRuntime.cs b/src/System.Management.Automation/engine/DefaultCommandRuntime.cs
index d45abaaffbc..48d74667dae 100644
--- a/src/System.Management.Automation/engine/DefaultCommandRuntime.cs
+++ b/src/System.Management.Automation/engine/DefaultCommandRuntime.cs
@@ -230,6 +230,7 @@ public PSTransactionContext CurrentPSTransaction
/// if it exists, otherwise throw an invalid operation exception.
///
/// The error record to throw.
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
public void ThrowTerminatingError(ErrorRecord errorRecord)
{
if (errorRecord.Exception != null)
diff --git a/src/System.Management.Automation/engine/ICommandRuntime.cs b/src/System.Management.Automation/engine/ICommandRuntime.cs
index 6f0b3ce9d57..03d983354f0 100644
--- a/src/System.Management.Automation/engine/ICommandRuntime.cs
+++ b/src/System.Management.Automation/engine/ICommandRuntime.cs
@@ -549,6 +549,7 @@ public interface ICommandRuntime
/// if any information is to be added. It should encapsulate the
/// error record into an exception and then throw that exception.
///
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
void ThrowTerminatingError(ErrorRecord errorRecord);
#endregion ThrowTerminatingError
#endregion misc
diff --git a/src/System.Management.Automation/engine/MshCommandRuntime.cs b/src/System.Management.Automation/engine/MshCommandRuntime.cs
index e43e49631aa..bf8fe32fd8e 100644
--- a/src/System.Management.Automation/engine/MshCommandRuntime.cs
+++ b/src/System.Management.Automation/engine/MshCommandRuntime.cs
@@ -2055,6 +2055,7 @@ public PSTransactionContext CurrentPSTransaction
/// .
/// etc.
///
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
public void ThrowTerminatingError(ErrorRecord errorRecord)
{
ThrowIfStopping();
diff --git a/src/System.Management.Automation/engine/cmdlet.cs b/src/System.Management.Automation/engine/cmdlet.cs
index b049193fd87..ba7548f982d 100644
--- a/src/System.Management.Automation/engine/cmdlet.cs
+++ b/src/System.Management.Automation/engine/cmdlet.cs
@@ -1714,6 +1714,7 @@ public PSTransactionContext CurrentPSTransaction
/// .
/// etc.
///
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
public void ThrowTerminatingError(ErrorRecord errorRecord)
{
using (PSTransactionManager.GetEngineProtectionScope())
diff --git a/src/System.Management.Automation/namespaces/ProviderBase.cs b/src/System.Management.Automation/namespaces/ProviderBase.cs
index 4ffc26db093..7379e422856 100644
--- a/src/System.Management.Automation/namespaces/ProviderBase.cs
+++ b/src/System.Management.Automation/namespaces/ProviderBase.cs
@@ -1417,6 +1417,7 @@ public virtual string GetResourceString(string baseName, string resourceId)
#region ThrowTerminatingError
///
+ [System.Diagnostics.CodeAnalysis.DoesNotReturn]
public void ThrowTerminatingError(ErrorRecord errorRecord)
{
using (PSTransactionManager.GetEngineProtectionScope())