diff --git a/Tasks/Common/PowershellHelpers/Invoke-ActionWithRetries.ps1 b/Tasks/Common/PowershellHelpers/Invoke-ActionWithRetries.ps1 index 6f9968c769d7..99f9b7edfd2c 100644 --- a/Tasks/Common/PowershellHelpers/Invoke-ActionWithRetries.ps1 +++ b/Tasks/Common/PowershellHelpers/Invoke-ActionWithRetries.ps1 @@ -86,7 +86,7 @@ function Test-RetryableException { ) $AllowedExceptions | ForEach-Object { - if($_ -and ([type]$_).IsAssignableFrom($Exception.GetType())) + if($_ -and ($Exception -is ([type]$_))) { return $true; } diff --git a/Tasks/Common/PowershellHelpers/Tests/Invoke-ActionWithRetries.ShouldRetryOnException.ps1 b/Tasks/Common/PowershellHelpers/Tests/Invoke-ActionWithRetries.ShouldRetryOnException.ps1 index 38fc54c378c9..325f4f300e21 100644 --- a/Tasks/Common/PowershellHelpers/Tests/Invoke-ActionWithRetries.ShouldRetryOnException.ps1 +++ b/Tasks/Common/PowershellHelpers/Tests/Invoke-ActionWithRetries.ShouldRetryOnException.ps1 @@ -16,6 +16,6 @@ Register-Mock Start-Sleep {} # Act/Assert. Assert-Throws { - & $module Invoke-ActionWithRetries -Action $action -RetryableExceptions @("System.IO.FileNotFoundException") + & $module Invoke-ActionWithRetries -Action $action -RetryableExceptions @("System.IO.IOException") } -MessagePattern "File not found error!" Assert-AreEqual 10 $global:retriesAttempted "Number of retries not correct"