Forum Discussion

Oliver Zeiser's avatar
Oliver Zeiser
Brass Contributor
Oct 18, 2016

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

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

  • Cdupret's avatar
    Cdupret
    Copper Contributor

    Oliver Zeiser

    Another way to do it is to create and use a Web Service that is using SharePoint Powershell to create a site collection.

     

    I'm using it with multiple site collections created on the same time without any problem.

  • Debayo Graham's avatar
    Debayo Graham
    Brass Contributor

    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

  • 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/TenantExtensions.cs) 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

     

     

    • VesaJuvonen's avatar
      VesaJuvonen
      Icon for Microsoft rankMicrosoft

      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.

      • Bernd Rickenberg's avatar
        Bernd Rickenberg
        Brass Contributor

        I am using PnP Core 1702 release in two different production tenants. The problem seems to be solved after the PnP core update in one tenant but persists in the other tenant.

         

        After digging into it I found a solution for my case as I am using PnP Partner Pack (1702 release). The SiteCollectionProvisioningJobHandler accesses the same Tenant instance after the site collection was created and fails with the exception: "Operation is not valid due to the current state of the object."

         

        Instead of using the same instance (as Vesa mentioned), I create a new ClientContext and with that a new Tenant instance and provisioning works fine. I will create a pull request in the PnP Partner Pack repo with the work-around described.

         

        Update (28-02-2017)

        I found this to still fail occasionally. Also, when using a retry pattern with e.g. 10 retries and 10 seconds in between, it still fails. Best options seems currently to avoid working with the tenant object after creating a site collection.

  • ray hogan's avatar
    ray hogan
    Copper Contributor

    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.

  • 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.

  • 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/

     

    • Oliver Zeiser's avatar
      Oliver Zeiser
      Brass Contributor

      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.

      • Vel Senthil's avatar
        Vel Senthil
        Copper Contributor

        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)

Resources