Forum Discussion
SharePoint Online issues creating site collections via PnP code again...
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
- VesaJuvonenJan 21, 2017
Microsoft
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 RickenbergFeb 22, 2017Brass 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.
- Venkata Ratnam VemulaMay 11, 2017Brass Contributor
Occassionally, it is failing with the following error:
Is there a permanent fix for this issue?
[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) at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay) at Provisioning.Infrastructure.Jobs.Handlers.SiteCollectionProvisioningJobHandler.CreateSiteCollection(SiteCollectionProvisioningJob job) 0ms 2017-05-10 21:03:20.9868 [OfficeDevPnP.Core] [0] [Debug] AuthenticationManager:EnsureToken(siteUrl:https://abc.com/infrastructure-Prod,realm:f9914f5c-6fc2-4043-9c04-6ccec0b819f5,appId:b7f97e11-3746-4392-b871-e3f0dc5fd615,appSecret:PRIVATE) 0ms
- Debayo GrahamJan 25, 2017Brass Contributor
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
- Venkata Ratnam VemulaJan 26, 2017Brass Contributor
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
- Oliver ZeiserJan 23, 2017Brass Contributor
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.