Quick Solution 6 : Group Cannot be found

Error Message 

<date time>  w3wp.exe (0x2EF0)                        0x4084 SharePoint Foundation          Runtime                        tkau Unexpected Microsoft.SharePoint.SPException: Group cannot be found.    at Microsoft.SharePoint.ApplicationPages.PeoplePage.get_CurrentGroup()     at Microsoft.SharePoint.ApplicationPages.PeoplePage.OnLoad(EventArgs e)     at System.Web.UI.Control.LoadRecursive()     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 2a23135d-6a07-4230-b2bf-d3a03f0acafc
<date time>  w3wp.exe (0x2EF0)                        0x4084 SharePoint Foundation          Monitoring                     b4ly Medium   Leaving Monitored Scope (Request (GET:https://<site>:80/_layouts/people.aspx?MembershipGroupId=<group id>)). Execution Time=37.5787984227046 2a23135d-6a07-4230-b2bf-d3a03f0acafc
 

Causes 

The issue happens when the current group(MembershipGroupId from query string) is not in the web associated groups. SharePoint uses the following way to check if a group is existing in the web associated groups.

  1. Get a dictionary named “ReferencedGroups”
    1. Get a semicolon spited string(strAssociatedGroups) that indicate the groups that are associated with current web:
          string strAssociatedGroups = Web.AllProperties[“vti_associategroups”] as string
    2. Get all unique Ids(groupIds) from the AssociatedGroupsString, and store them in a collection.
    3. Get the associated groups based on the collection we got from step 2:
          Web.SiteGroups.GetCollection(groupIds.ToArray())
    4. Use a Dictionary to store the groups with groupId(SPGroup.Id) as key and group(SPGroup) as value.
  2. Check if the current group is existing in the ReferencedGroups dictionary.
    1. ReferencedGroups.TryGetValue(GroupId, out m_currentGroup). The parameter GroupId is got from the query string “MembershipGroupId”.
    2. If m_currentGroup is null, the “Group cannot be found” will be shown

 Solutions 

Add the group to associated groups using the following code:

 SPSite site = new SPSite("site’s URL");
 SPWeb web = site.OpenWeb();
 SPUser user = web.CurrentUser;
 web.SiteGroups.Add("group name", user, user, "description");
 SPGroup g = web.SiteGroups["group name"];
 web.AssociatedGroups.Add(g);
 web.Update();

Or, add the group’s id to the associategroups property directly using PowerShell:

 $site = Get-SPSite <site’s URL>
 $web = $site.OpenWeb()
 $associategroups = $web.Properties["vti_associategroups"]
 $web.Properties["vti_associategroups"] = $associategroups + “;” + <the group’s id>
 $web.Properties.Update()