Weird Exception when Creating a Web Programatically
Sorry I haven't posted for a long time, but I've been mega-busy working on various SharePoint goodies and haven't found the time . . .
My latest problem I'm seeing revolves around programatically creating a web i.e. creating a sub-site. I need to create a custom web service, and one of the methods on that web service must create a site - easy you'd think. I used the following code:
analysisSite = new SPSite(DealSiteHelper.AnalysisWebURL);
analysisWeb = analysisSite.OpenWeb();
analysisWeb.AllowUnsafeUpdates = true;
SPWeb newWeb = analysisWeb.Webs.Add(webUrl, title, title, 1033, "STS", true, false);
analysisWeb.AllowUnsafeUpdates = false;
However when the code hit the line where we are adding the new web to the Webs collection I get a Null Reference Exception with the following stack trace:
at Microsoft.SharePoint.SPSite.get_Features()
at Microsoft.SharePoint.SPElementProvider.QueryForWorkflowDefinitions(SPWeb web)
at Microsoft.SharePoint.Workflow.SPWorkflowManager. RegisterFeatureTemplates(SPWorkflowTemplateCollection wftemplates, SPWeb web)
at Microsoft.SharePoint.SPWeb.get_WorkflowTemplates()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation. get_BaseTemplate()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation. get_BaseTemplateInternal()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation.SetTaskList(SPList list)
at Microsoft.SharePoint.Workflow.SPWorkflowAssociationCollection. SetUtilityLists(SPWorkflowAssociation wa, Boolean forceUtilityListCreation)
at Microsoft.SharePoint.Workflow.SPWorkflowAssociationCollection. AddCore(SPWorkflowAssociation wa, Guid id, SPList list, Boolean forceUtilityListCreation)
at Microsoft.SharePoint.Workflow. SPContentTypeWorkflowAssociationCollection. AddCoreCT(SPWorkflowAssociation associationTemplate)
at Microsoft.SharePoint.Workflow. SPContentTypeWorkflowAssociationCollection. UpdateOrAdd(SPWorkflowAssociation associationTemplate)
at Microsoft.SharePoint.SPContentType.CopyWorkflowAssociationsTo(SPContentType ctDst)
at Microsoft.SharePoint.SPWeb.SyncNewLists()
at Microsoft.SharePoint.SPWeb.ApplyWebTemplate(String strWebTemplate)
at Microsoft.SharePoint.SPWeb.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)
at Microsoft.SharePoint.SPWeb.SPWebCollectionProvider.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)
at Microsoft.SharePoint.SPWebCollection.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
at Company.SharePoint.AnalysisExecution.DealSiteWebService.CreateDealSite(String title) in D:\\My Documents\\Visual Studio 2005 Projects\\DealSiteWebService\\DealSiteWebService.asmx.cs:line 40
If I extract the above code and place it in a normal Windows Console Application, then everything works OK - this exception only occurs when I call this code in a web service method.
I've come accross the same problem mentioned on Todd Baginski's blog, but I don't think he's found a solution yet either.
If I ever manage to work out what this problem is I shall post again, but in the mean time lets hope that it's fixed in TR :)
My latest problem I'm seeing revolves around programatically creating a web i.e. creating a sub-site. I need to create a custom web service, and one of the methods on that web service must create a site - easy you'd think. I used the following code:
analysisSite = new SPSite(DealSiteHelper.AnalysisWebURL);
analysisWeb = analysisSite.OpenWeb();
analysisWeb.AllowUnsafeUpdates = true;
SPWeb newWeb = analysisWeb.Webs.Add(webUrl, title, title, 1033, "STS", true, false);
analysisWeb.AllowUnsafeUpdates = false;
However when the code hit the line where we are adding the new web to the Webs collection I get a Null Reference Exception with the following stack trace:
at Microsoft.SharePoint.SPSite.get_Features()
at Microsoft.SharePoint.SPElementProvider.QueryForWorkflowDefinitions(SPWeb web)
at Microsoft.SharePoint.Workflow.SPWorkflowManager. RegisterFeatureTemplates(SPWorkflowTemplateCollection wftemplates, SPWeb web)
at Microsoft.SharePoint.SPWeb.get_WorkflowTemplates()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation. get_BaseTemplate()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation. get_BaseTemplateInternal()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation.SetTaskList(SPList list)
at Microsoft.SharePoint.Workflow.SPWorkflowAssociationCollection. SetUtilityLists(SPWorkflowAssociation wa, Boolean forceUtilityListCreation)
at Microsoft.SharePoint.Workflow.SPWorkflowAssociationCollection. AddCore(SPWorkflowAssociation wa, Guid id, SPList list, Boolean forceUtilityListCreation)
at Microsoft.SharePoint.Workflow. SPContentTypeWorkflowAssociationCollection. AddCoreCT(SPWorkflowAssociation associationTemplate)
at Microsoft.SharePoint.Workflow. SPContentTypeWorkflowAssociationCollection. UpdateOrAdd(SPWorkflowAssociation associationTemplate)
at Microsoft.SharePoint.SPContentType.CopyWorkflowAssociationsTo(SPContentType ctDst)
at Microsoft.SharePoint.SPWeb.SyncNewLists()
at Microsoft.SharePoint.SPWeb.ApplyWebTemplate(String strWebTemplate)
at Microsoft.SharePoint.SPWeb.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)
at Microsoft.SharePoint.SPWeb.SPWebCollectionProvider.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)
at Microsoft.SharePoint.SPWebCollection.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
at Company.SharePoint.AnalysisExecution.DealSiteWebService.CreateDealSite(String title) in D:\\My Documents\\Visual Studio 2005 Projects\\DealSiteWebService\\DealSiteWebService.asmx.cs:line 40
If I extract the above code and place it in a normal Windows Console Application, then everything works OK - this exception only occurs when I call this code in a web service method.
I've come accross the same problem mentioned on Todd Baginski's blog, but I don't think he's found a solution yet either.
If I ever manage to work out what this problem is I shall post again, but in the mean time lets hope that it's fixed in TR :)