From 60c701646a4d6e7692f46439f34762720c3b1ca6 Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Fri, 13 Nov 2026 18:16:28 +0000 Subject: [PATCH 1/3] potential fix for bug #5477 --- src/Commands/Principals/GetUser.cs | 66 +++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/src/Commands/Principals/GetUser.cs b/src/Commands/Principals/GetUser.cs index b73a9a268..f20fb2b39 100644 --- a/src/Commands/Principals/GetUser.cs +++ b/src/Commands/Principals/GetUser.cs @@ -40,6 +40,31 @@ public class DetailedUser public GroupCollection Groups { get; set; } } + private bool TryExecuteWithRetry(Action action, string operationDescription) + { + int MaxRetryAttempts = 5; + for (var attempt = 1; attempt <= MaxRetryAttempts; attempt++) + { + try + { + action(); + return true; + } + catch (Exception ex) + + { + if (attempt == MaxRetryAttempts) + { + LogWarning($"{operationDescription} failed after {MaxRetryAttempts} attempts: {ex.Message}"); + return false; + } + + LogWarning($"{operationDescription} failed on attempt {attempt} of {MaxRetryAttempts}. Retrying. Error: {ex.Message}"); + } + } + return false; + } + protected override void ExecuteCmdlet() { DefaultRetrievalExpressions = new Expression>[] @@ -200,21 +225,34 @@ protected override void ExecuteCmdlet() foreach (var listItem in item) { LogDebug(string.Format("Enumerating though listitems")); - listItem.EnsureProperty(i => i.HasUniqueRoleAssignments); - - if (listItem.HasUniqueRoleAssignments) + try { - string listItemUrl = listItem["FileRef"].ToString(); - LogDebug(string.Format("List item {0} HasUniqueRoleAssignments", listItemUrl)); - - CurrentWeb.Context.Load(listItem.RoleAssignments, r => r.Include( - ra => ra.RoleDefinitionBindings, - ra => ra.Member.LoginName, - ra => ra.Member.Title, - ra => ra.Member.PrincipalType)); - CurrentWeb.Context.ExecuteQueryRetry(); - - users.AddRange(GetPermissions(listItem.RoleAssignments, listItemUrl)); + listItem.EnsureProperty(i => i.HasUniqueRoleAssignments); + + if (listItem.HasUniqueRoleAssignments) + { + string listItemUrl = listItem["FileRef"].ToString(); + LogDebug(string.Format("List item {0} HasUniqueRoleAssignments", listItemUrl)); + + if (!TryExecuteWithRetry(() => + { + CurrentWeb.Context.Load(listItem.RoleAssignments, r => r.Include( + ra => ra.RoleDefinitionBindings, + ra => ra.Member.LoginName, + ra => ra.Member.Title, + ra => ra.Member.PrincipalType)); + CurrentWeb.Context.ExecuteQueryRetry(); + }, $"Loading role assignments for list item {listItemUrl}")) + { + continue; + } + + users.AddRange(GetPermissions(listItem.RoleAssignments, listItemUrl)); + } + } + catch (Exception ex) + { + LogWarning($"Failed to process list item {listItem.Id}: {ex.Message}"); } } } From cd2085a6467f84c32030d65944aefe78188f5959 Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Fri, 13 Nov 2026 18:20:14 +0000 Subject: [PATCH 2/3] Update to add try catch --- src/Commands/Principals/GetUser.cs | 46 +++++------------------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/src/Commands/Principals/GetUser.cs b/src/Commands/Principals/GetUser.cs index f20fb2b39..6af37093c 100644 --- a/src/Commands/Principals/GetUser.cs +++ b/src/Commands/Principals/GetUser.cs @@ -40,31 +40,6 @@ public class DetailedUser public GroupCollection Groups { get; set; } } - private bool TryExecuteWithRetry(Action action, string operationDescription) - { - int MaxRetryAttempts = 5; - for (var attempt = 1; attempt <= MaxRetryAttempts; attempt++) - { - try - { - action(); - return true; - } - catch (Exception ex) - - { - if (attempt == MaxRetryAttempts) - { - LogWarning($"{operationDescription} failed after {MaxRetryAttempts} attempts: {ex.Message}"); - return false; - } - - LogWarning($"{operationDescription} failed on attempt {attempt} of {MaxRetryAttempts}. Retrying. Error: {ex.Message}"); - } - } - return false; - } - protected override void ExecuteCmdlet() { DefaultRetrievalExpressions = new Expression>[] @@ -234,27 +209,20 @@ protected override void ExecuteCmdlet() string listItemUrl = listItem["FileRef"].ToString(); LogDebug(string.Format("List item {0} HasUniqueRoleAssignments", listItemUrl)); - if (!TryExecuteWithRetry(() => - { - CurrentWeb.Context.Load(listItem.RoleAssignments, r => r.Include( - ra => ra.RoleDefinitionBindings, - ra => ra.Member.LoginName, - ra => ra.Member.Title, - ra => ra.Member.PrincipalType)); - CurrentWeb.Context.ExecuteQueryRetry(); - }, $"Loading role assignments for list item {listItemUrl}")) - { - continue; - } + CurrentWeb.Context.Load(listItem.RoleAssignments, r => r.Include( + ra => ra.RoleDefinitionBindings, + ra => ra.Member.LoginName, + ra => ra.Member.Title, + ra => ra.Member.PrincipalType)); + CurrentWeb.Context.ExecuteQueryRetry(); users.AddRange(GetPermissions(listItem.RoleAssignments, listItemUrl)); } } catch (Exception ex) { - LogWarning($"Failed to process list item {listItem.Id}: {ex.Message}"); + LogWarning(string.Format("Error while enumerating listitem {0} in list {1} in site {2} with error {3}", listItem.Id, list.RootFolder.ServerRelativeUrl, CurrentWeb.Url, ex.Message)); } - } } itemProgress.RecordType = ProgressRecordType.Completed; WriteProgress(itemProgress); From 4ab8dd7d147f0cac998b4637b2e82ca679722e0c Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Fri, 13 Nov 2026 18:23:12 +0000 Subject: [PATCH 3/3] update missing bracket --- src/Commands/Principals/GetUser.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/Principals/GetUser.cs b/src/Commands/Principals/GetUser.cs index 6af37093c..ba2abb8d9 100644 --- a/src/Commands/Principals/GetUser.cs +++ b/src/Commands/Principals/GetUser.cs @@ -223,6 +223,7 @@ protected override void ExecuteCmdlet() { LogWarning(string.Format("Error while enumerating listitem {0} in list {1} in site {2} with error {3}", listItem.Id, list.RootFolder.ServerRelativeUrl, CurrentWeb.Url, ex.Message)); } + } } itemProgress.RecordType = ProgressRecordType.Completed; WriteProgress(itemProgress);