diff --git a/Engine/Helper.cs b/Engine/Helper.cs
index 5af3a9fcf..d0144814b 100644
--- a/Engine/Helper.cs
+++ b/Engine/Helper.cs
@@ -292,6 +292,30 @@ public bool IsDscResourceModule(string filePath)
return false;
}
+
+ ///
+ /// Gets the module manifest with retries to compensate for sporadic faiures to thread safety bugs in PowerShell.
+ ///
+ ///
+ ///
+ /// Returns a object of type PSModuleInfo
+ public PSModuleInfo GetModuleManifestWithRetry(string filePath, out IEnumerable errorRecord)
+ {
+ CmdletInvocationException cmdletInvocationException = null;
+ for (int attempt = 0; attempt < 3; attempt++)
+ {
+ try
+ {
+ return GetModuleManifest(filePath, out errorRecord);
+ }
+ catch (CmdletInvocationException exception)
+ {
+ cmdletInvocationException = exception;
+ }
+ }
+ throw cmdletInvocationException;
+ }
+
///
/// Gets the module manifest
///
diff --git a/Rules/MissingModuleManifestField.cs b/Rules/MissingModuleManifestField.cs
index 78deb38ab..737ef9033 100644
--- a/Rules/MissingModuleManifestField.cs
+++ b/Rules/MissingModuleManifestField.cs
@@ -40,7 +40,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
if (Helper.IsModuleManifest(fileName))
{
IEnumerable errorRecords;
- var psModuleInfo = Helper.Instance.GetModuleManifest(fileName, out errorRecords);
+ var psModuleInfo = Helper.Instance.GetModuleManifestWithRetry(fileName, out errorRecords);
if (errorRecords != null)
{
foreach (var errorRecord in errorRecords)
diff --git a/Rules/UseToExportFieldsInManifest.cs b/Rules/UseToExportFieldsInManifest.cs
index bfd99db9e..19e4fee32 100644
--- a/Rules/UseToExportFieldsInManifest.cs
+++ b/Rules/UseToExportFieldsInManifest.cs
@@ -51,7 +51,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
// check if valid module manifest
IEnumerable errorRecord = null;
- PSModuleInfo psModuleInfo = Helper.Instance.GetModuleManifest(fileName, out errorRecord);
+ PSModuleInfo psModuleInfo = Helper.Instance.GetModuleManifestWithRetry(fileName, out errorRecord);
if ((errorRecord != null && errorRecord.Count() > 0) || psModuleInfo == null)
{
yield break;