After unsetting MDS or something break permissions inheritance and update web, I am getting this error, I am creating 10 subwebs and it throws error in 5th one, I am opening new SPSite each time creating a new subweb,
Code
using (SPSite siteCol = new SPSite(siteURL)) using (SPWeb web = siteCol.OpenWeb()) { SPWebTemplate template = GetTemplateFromWeb(web, sTemplate); using (SPWeb newWeb = web.Webs.Add(shortURL, sTitle, string.Empty, web.Language, template, false, false)) { AddPropertyToWeb(newWeb, "PAGETYPE"", ""PBV"); AddWebPartToWeb(newWeb, new sMenu(), "left"); AddWebPartToWeb(newWeb, new sDetails(), "right"); SetUnsetMDSFeature(newWeb); //BreakPermissionsInheritance(newWeb); } } private void SetUnsetMDSFeature(SPWeb newWeb) { try { newWeb.AllowUnsafeUpdates = true; newWeb.EnableMinimalDownload = false; newWeb.Update(); // Exception arises here } finally { newWeb.AllowUnsafeUpdates = false; } } Just Exception
The web being updated was changed by an external process.
Exception - Stack
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.SetWebProps(String bstrUrl, String bstrTitle, String bstrDescription, UInt32 nLocale, UInt16 nTimeZone, Boolean bTime24, Int16 nCalendarType, Int16 nAdjustHijriDays, Int16 nAltCalendarType, Boolean bShowWeeks, Int16 nFirstWeekOfYear, Int16 nFirstDayOfWeek, Int16 nWorkDays, Int16 nWorkDayStartHour, Int16 nWorkDayEndHour, Int32 lFlags, Int32 lDontIgnoreFlagsMask, Int16 nCollation, UInt32 nAuthor, String bstrThemedCssFolderUrl, String bstrCustomizedCssFileList, String bstrAlternateCssUrl, String bstrAlternateHeaderUrl, String bstrMasterUrl, String bstrCustomMasterUrl, String bstrCustomJSUrl, String bstrSiteLogoUrl, String bstrSiteLogoDescription, Boolean bUpdateTimeCreated, DateTime dtTimeCreated, Boolean bUpdateTimeLastModified, DateTime dtTimeLastModified, Boolean bOverwriteMUICultures, Boolean bMUIEnabled, String bstrAlternateMUICultures, Int32 uiVersion, Int16 nClientTag, UInt32& nCollationLCID) at Microsoft.SharePoint.SPWeb.Update() at Deployment.WebServices.Internal.Deployment.SetUnsetMDSFeature(SPWeb newWeb) at Deployment.WebServices.Internal.Deployment.DeployDecisions(String pSchemeURL, Int32 lcid) at SyncInvokeDeployDecisions(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
Edit - ANSWER THAT WORKED FOR ME
For now because I am adding several sites and then other operations on them + SOME OTHER BUSINESS LOGIC (which takes some time), I am doing this at end by recalling all spwebs and disabling this feature.
In other Words I am using Thread.Sleep(10000), to give enough time for web provisioning.