We have code that does the following:
- Creates a new
SPWebprogrammatically within a site collection.
- Adds a new
SPGroupto the programmatically-created
spWeb.SiteGroups.Add(string name, SPMember owner, SPUser defaultUser, string description).
The invocation to add the SPGroup looks like this:
spWeb.SiteGroups.Add("Group Name", spWeb.Site.RootWeb.AssociatedOwnerGroup, spWeb.CurrentUser, "Group Description");
On all of our environments except for 1, this code works as expected. The
owner of the new
SPGroup is set to the
AssociatedOwnerGroup of the site collection's root web.
However on one of our environments,
spWeb.Site.RootWeb.AssociatedOwnerGroup is null, and thus the call to
spWeb.SiteGroups.Add throws an
ArgumentNullException for the
We have checked, and the root site collection's
Owners group is there.
What would cause
spWeb.Site.RootWeb.AssociatedOwnerGroup to return null?
spWeb.CurrentUser is a site collection administrator.
We have tried wrapping this in
SPSecurity.RunWithElevatedPrivileges, but the result is the same.