FBA Users in Groups in SubSites causes Object refernce not set to an instance of an object

I have found that I got the "Object reference not set to an instance of an object" error whenever I attempted to edit a FBA user that was in a SharePoint group that was in a sub-site that was not inheriting permissions from the parent root site. This was on the UserEdit.aspx page. This made me think that the issue was with the code attempting to check the box for the group that the user was in, however that item was not in the list of groups being retrieved, since it was only retrieving the SharePoint groups at the root site level. I then downloaded the code and in the UserEdit.aspx.cs I found that the groups are not displayed when the roles are activated (line 72). Next I went to the FBA Site Configuration screen and checked the Enable Roles checkbox. Sure enough I was then able to edit the FBA users without the error, as a work around. However to resolve the error I reviewed to code to determine why all the SharePoint groups for all the sites for the site collection were not being returned.

The root cause of this error is the binding of the groupList (the list of checkboxes for the SharePoint groups) being bound to this.Web.Groups. This "Gets the collection of cross-site groups for the site." The code to return all the SharePoint groups for all the sites groups would be SPContext.Current.Site.RootWeb.SiteGroups. This "Gets the collection of cross-site groups for the site collection."  This should be changed in the following locations within the UserEdit.aspx.cs and UserNew.aspx.cs files

UserEdit.aspx.cs

line 105 change groupList.DataSource = this.Web.Groups; to groupList.DataSource = SPContext.Current.Site.RootWeb.SiteGroups;

line 219 change this.Web.Groups[groupName].AddUser(spuser); to SPContext.Current.Site.RootWeb.SiteGroups[groupName].AddUser(spuser);

line 226 change this.Web.Groups[groupName].RemoveUser(spuser); to SPContext.Current.Site.RootWeb.SiteGroups[groupName].RemoveUser(spuser);

UserNew.aspx.cs

line 52 change groupList.DataSource = this.Web.Groups; to groupList.DataSource = SPContext.Current.Site.RootWeb.SiteGroups;

line 138 change SPGroup group = this.Web.Groups[groupList.Items[i].Value]; to SPGroup group = SPContext.Current.Site.RootWeb.SiteGroups[groupList.Items[i].Value];

Hope this helps anyone else experiencing the same issue that I was having.

Looks like this was fixed already by "Patch ID 10299. Changes by sigan. Fixes for work items 420,421,422. Fixed to use full group list using SPWeb.SiteGroups. Fixed bug if user was assigned to missing group. Cleaned up pointer to UserInformationList." http://sharepoint2010fba.codeplex.com/SourceControl/changeset/changes/10343

I just found this after my post, under the source code tab.

 

 

Thanks for catching this. The release with the fix in it should be out in the next couple of days - i'm just testing it as we speak.