Hi,
I'm trying to call CreateDefaultAssociatedGroups method in sandboxed feature.
I first call the BreakRoleInheritance method and then the CreateDefaultAssociatedGroups, and nothing happens but the BreakRoleInheritance.
if (!web.HasUniqueRoleAssignments) web.BreakRoleInheritance(false); web.CreateDefaultAssociatedGroups(web.Site.Owner.LoginName, null, web.Title); web.Update();
So I noticed that if the 3 spweb.Associated*Group variables are not null, the method CreateDefaultAssociatedGroups does nor create the web groups.
At this point I tried to set to null the 3 variables before the call to CreateDefaultAssociatedGroups method, but I got a null reference exception.
web.AssociatedVisitorGroup = null; web.AssociatedMemberGroup = null; web.AssociatedOwnerGroup = null;
Microsoft.SharePoint.UserCode.SPUserCodeSolutionProxiedException: Object reference not set to an instance of an object. Server stack trace: at Microsoft.SharePoint.SPWeb.AssociatedVisitorGroup__set(SPGroup value) at Microsoft.SharePoint.SPWeb.set_AssociatedVisitorGroup(SPGroup value)
At this point, I figured out that the only way to create the default groups is to initially create the web with inherintance broken, and this time all worked well!
The questions are:
- There is some bug?
- Why the BreakRoleInheritance method does not clean the Associated*Group variables?
- Why CreateDefaultAssociatedGroups does not create the groups if those variables aren't null?
- Why I can't set null the variables?
This beahavior is both in Sharepoint 2013, so the last question: why I can't use this API in Online environment?