SharePoint Online issues creating site collections via PnP code again...

Brass Contributor

We are seeing issues when creating new sites via the PnP Core extension method AddSiteCollection. We are seeing this on several customer tenants.

Can someone confirm that this is once again a SPO issue or has something changed in the PnP code that I am not aware of?

 

The issue does not occure all the time. It only fails about 50% of the times...

 

Microsoft.SharePoint.Client.ServerException: Operation is not valid due to the current state of the object. at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at Microsoft.SharePoint.Client.TenantExtensions.GetSiteGuidByUrl(Tenant tenant, Uri siteFullUrl) at Microsoft.SharePoint.Client.TenantExtensions.AddSiteCollection...

26 Replies

@Oliver Zeiser,

In general you get these error messages when multiple things update the same object.

 

So typically you could get this error when you create a site collection and while the site collection is being created it is also updated by another process.

 

So for example if you apply templates to a site twice at the same time. The context of the command giving the error is then not up to date any more as the context isn't updated with updates made by the other process.

 

In the past I found this error when we had mutliple developers runninng powershell commands applying PnP templates to the same site. We then had to reconnect to the site to bring the context into sync.

 

The slightly less obvious variations of the same problem occur if your tmeplate include multiple copies of the same object (list, column, contenttype). So during a single application of a template an object is updated twice.

 

The easiest way to debug the issue I found is either with PowerShell apply a template after having enabled debug (Set-SPOTraceLog) or to step through the code and enable debug on the PnP.

 

Hopefully the following two artciles will help you:

 

https://veenstra.me.uk/2016/10/11/office-365-how-do-debug-pnp-powershell-commands/

 

https://veenstra.me.uk/2016/07/29/office-365-sharepoint-how-to-debug-pnp-provisioning-engine/

 

Thank you for your response.

I am not using the provisioning engine, just a simple csom call to create a blank team site. There are no other requests to this site during this time.

For me this is clearly a bug in SPO or something changed and the PnP extension needs an update. But since there are probably many others, using this PnP extension, i was wondering if other people have also seen this and maybe opend support cases already and can provide some more information on this topic.

So the way I understand this, there is nothing I can do about it from my code perspective.

I am facing the same issue. In my case, I am using Azure webjob to create the site. This error happens before applying the template.

Here is the stack trace:

at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay)
at Microsoft.SharePoint.Client.TenantExtensions.GetSiteGuidByUrl(Tenant tenant, Uri siteFullUrl)
at Microsoft.SharePoint.Client.TenantExtensions.CreateSiteCollection(Tenant tenant, SiteEntity properties, Boolean removeFromRecycleBin, Boolean wait)

Yup that is the same issue. I am seeing this at more than 15 customers. But many others are just working fine. And I have the same code running there. So I guess only a few tenants/sharepoint online farms have this issue.

It is a big pain that the key feature of sharepoint online, creating sitecollections, is not working reliable. I am still not quite sure if the issue only shows up with PnP library or also using ootb csom methods. I guess i'll have to check that first before opening one more support case....

So here is a quick update: The issue still persists on many tenants, so let me provide some more info on this issue.

The problem is, that the SpoOperation returns IsComplete even if the site is not really provisioned. Even worse, when getting the site status via Tenant.GetSitePropertiesByUrl it will report "Active" although the real status is still "Creating". This is why the PnP CreateSite method fails when trying to get the site guid, since this one still does not exist.

Only workaround I have found so far is to wait in a back-off try-catch loop for the site to be really provisioned.

Its a big pain since this basic feature in SPO shoud just work...., but maybe this helps someone....

I'm experiencing the same behaviour in at least three tenants (haven't tested more at this point). I'm not using PnP extension methods for creation. The issue seems to come more often when creating multiple site collections in a row, using Azure continuous webjob.

Wer are also still seeing this on many tenants. MS doesn't seem to care though. I guess they are busy figuring out new ways on how to prevent or break customizations ;)

Just build your own retry logic. You will be better off trying to fix it yourself than hoping for MS to fix it. Since it is related to code, support tickets won't help you.

Same issue. Sporadic error, hard to repeat, too. Noticed it happening when the tenant load/usage is higher.  Went and implemented the workaround with the loop.

We are also seeing this issue. It's extremely frustrating as we are trying to deliver a robust provisioning solution to our customers but are impeded by this seemingly inconsistent issue. Most sites go through end-to-end no problem, but every now and then a site will bomb out. The site collection will still get created but the provisioning code will bomb out with:

 

"Operation is not valid due to the current state of the object"

at 

tenant.CreateSiteCollection(newSite, true, true);

 

We are attempting to wrap this in some retry logic but we really shouldn't have to. Please fix this Microsoft.

I was just checking the PnP code for sitecollection creation (we are using the CreateSiteCollection tenant extension method: https://github.com/SharePoint/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/AppModelExtensions/T...) and there seems to be a wait function to wait for the creation of the site collection but more interestingly there is also this comment which could explain the error you are receiving:

 

// Eat all exceptions cause there's currently (December 16) an issue in the service that can make this call fail in combination with app-only usage

 

 

Like mentioned by Süleyman Ayazalp, we did add workaround for this issue. Issue is in the oob CSOMs and it's being addressed, but we don't yet have exact date to get this solved. You can run into these issues if you provision site collection using app-only access and then try to access that site collection with Tenant object.

 

Fix is work in progress, but workarounds are also available

  • If you use PnP extensions to create site collections - Update to latest PnP NuGet package
  • If you use native CSOM APIs, remove any code accessing newly created site collection with Tenant object

 

If you are running into this issue and have opportunity to open officialy Premier Support case with Microsoft, that would be also appreciated. This is mainly for the sake of getting more details on the scale of the issue and who are suffering on that. We are working on a fix, but priorities are being always set by metrics based on officially reported issues.

Thanks for the info Vesa. Customer has already opened a support case on this.

Maybe slightly off-topic: What is the best premier support offer to get support for code related things in SPO? There are several offers (https://www.microsoft.com/en-us/microsoftservices/support.aspx) but none of them mentions SharePoint Online for developers.

I am gettting this error as well and all i am doing is seting the properies for the new site collection and using this code to attempt the creation. 

 

tenant.CreateSiteCollection(newSite, true, true);

 

I do notice the site collection is created but it errors out at that specific line

This helped me

 

  • If you use PnP extensions to create site collections - Update to latest PnP NuGet package

Update

It seems after a few tries i still get this error after updating

 

From which version did you update? What is the latest version you have updated?

Currently, I am using v2.6.1608 in which I am having the following issue. Do we need to take care of anything while updating to new PnP version?

 

[Error]	   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay) in C:\Code\pnp-sites-core-Aug\Core\OfficeDevPnP.Core\AppModelExtensions\ClientContextExtensions.cs:line 80
   at Microsoft.SharePoint.Client.TenantExtensions.GetSiteGuidByUrl(Tenant tenant, Uri siteFullUrl) in C:\Code\pnp-sites-core-Aug\Core\OfficeDevPnP.Core\AppModelExtensions\TenantExtensions.cs:line 372
   at Microsoft.SharePoint.Client.TenantExtensions.CreateSiteCollection(Tenant tenant, SiteEntity properties, Boolean removeFromRecycleBin, Boolean wait

 

@Venkata Ratnam Vemula
I got back the error after a few tries... Made ammendment to my previous post

Is there a workaround of fix for this issue?Its failing 50%.

Hi Oliver,

Could you please share the workaround logic (Source code)