I am trying to create a custom workflow activity to create a subsite as a sandboxed solution. I know the site creation works, but the workflow throws a time out error (the site creation finishes after the error is thrown). I assume this means that when I go to implement the rest of the workflow (populating a list and breaking inheritance if necessary) that the steps will be prevented.

The log output:

02/06/2012 14:54:53.67 w3wp.exe (0x1F98) 0x1BD8 SharePoint Foundation Workflow Infrastructure 98d4 Unexpected Microsoft.SharePoint.UserCode.SPUserCodeExecutionPipelineFailedException: Timeout while waiting for sandboxed code execution request to complete within the worker process. Server stack trace: at Microsoft.SharePoint.UserCode.SPUserCodeWorkerProcess.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, SPUserToken userToken, String currentAffinity, SPUserCodeExecutionContext executionContext) at Microsoft.SharePoint.UserCode.SPUserCodePoolableProcessConnection.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, SPUserToken userToken, String affinity, SPUserCodeExecutionContext executionContext) at Microsoft.SharePoint.UserCode.SPUserCodeExecutionHost.Execute(Type userCod...
02/06/2012 14:54:53.67* w3wp.exe (0x1F98) 0x1BD8 SharePoint Foundation Workflow Infrastructure 98d4 Unexpected ...eWrapperType, Guid siteCollectionId, SPUserToken userToken, String affinity, SPUserCodeExecutionContext executionContext) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.SharePoint.Administration.ISPUserCodeExecutionHostProxy.Execute(Type userCodeWrapperType, Guid siteCollectionI...
02/06/2012 14:54:53.67* w3wp.exe (0x1F98) 0x1BD8 SharePoint Foundation Workflow Infrastructure 98d4 Unexpected ...d, SPUserToken userToken, String affinityBucketName, SPUserCodeExecutionContext executionContext) at Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.Execute(Type userCodeWrapperType, SPSite site, SPUserCodeExecutionContext executionContext) at Microsoft.SharePoint.WorkflowActions.SPUserCodeWorkflowActivity.ExecuteUserCode() at Microsoft.SharePoint.WorkflowActions.SPUserCodeWorkflowActivity.System.Workflow.ComponentModel.IActivityEventListener<System.Workflow.ComponentModel.ActivityExecutionStatusChangedEventArgs>.OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e) at System.Workflow.ComponentModel.ActivityExecutorDelegateInfo
1.ActivityExecutorDelegateOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run(...
02/06/2012 14:54:53.67* w3wp.exe (0x1F98) 0x1BD8 SharePoint Foundation Workflow Infrastructure 98d4 Unexpected ...)

Eventually this will create the site based on a list item

namespace CreateSubsite {
class CreateSubsite {
    public static Hashtable createSite(SPUserCodeWorkflowContext context) {
        Hashtable result = new Hashtable();

        try {
            using (SPSite site = new SPSite(context.SiteUrl)) {
                using (SPWeb web = site.OpenWeb()) {
                    SPWebTemplate spWebTemplate = web.Site.GetWebTemplates(1033)["STS#1"];

                    //get the template
                    foreach (SPWebTemplate temp in web.Site.GetWebTemplates(1033)) {
                        if (temp.Title == "CI Template") {
                            spWebTemplate = temp;
                            break;
                        }
                    }

                    //strip special characters for address
                    string siteAddress = "New2";
                    string siteTitle = "New Site";

                    string description = "";
                    //create new site
                    using (site.AllWebs.Add(siteAddress, siteTitle, description,
                        1033, spWebTemplate, false, false)) {
                    }
                }
            }
            result["result"] = "Success";
        } catch (Exception e) {
            result["result"] = "Failure";
        }
        return result;
    }
}

}

Elements file:

<?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <WorkflowActions>
            <Action Name="Create Site"
                SandboxedFunction ="true"
                Assembly ="CreateSubsite, Version=1.0.0.0, Culture = neutral, PublicKeyToken=f9bbeb4405a11bcd"
                ClassName ="CreateSubsite.CreateSubsite"
                FunctionName ="createSite"
                AppliesTo ="all"
                Category ="Custom Actions">
  <RuleDesigner Sentence="Create Site">
  </RuleDesigner>
  <Parameters>
    <Parameter Name="__Context"
               Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, 
               Microsoft.SharePoint.WorkflowActions"
               Direction="In"
               DesignerType="Hide" />
  </Parameters>
</Action>

I think the only other notable aspects of this are that I created a strongly named key (which other than creating, I haven't touched) and that I have to reinstall the assembly on the GAC every time I want to deploy a change to the workflow action.

Thanks

link|improve this question
feedback

1 Answer

up vote 0 down vote accepted

I found http://stackoverflow.com/questions/5722320/sharepoint-2010-sandbox-solution-timeout

and am running under the assumption that it times out because my vm is slow. If my code isn't optimized, I would still like to have advice on it.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.