Breaking change on creating content types using CSOM - Value cannot be null
Category
- [ ] Question
- [ ] Typo
- [x] Bug
- [ ] Additional article idea
When applying PnPTemplate that contains a content type definition, provisioning fails with the error: "Apply-PnPProvisioningTemplate : Value cannot be null. Parameter name: s"
I have observed the problem on 14.05.2019 without changes to PnP engine version (used the latest one). I believe that the problem is not related to PnP but to O365 backend. Sample template definition that fails:
<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2018/05/ProvisioningSchema">
<pnp:Preferences Generator="OfficeDevPnP.Core, Version=2.20.1711.0, Culture=neutral, PublicKeyToken=3751622786b357c2" />
<pnp:Templates ID="TEST-TEMPLATES">
<pnp:ProvisioningTemplate ID="TEST" Version="1" Scope="RootSite">
<pnp:SiteFields>
<Field Type="Text" DisplayName="TestField" Name="TestField" StaticName="TestField" Description="TestField" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Group="TEST" ID="{b280c2fa-7aba-40a2-8d9a-e2e23984c305}" SourceID="{{siteid}}" ></Field>
</pnp:SiteFields>
<pnp:ContentTypes>
<pnp:ContentType ID="0x0100240A55DF4AAE484BAFA63308338F5501" Name="TestCT" Description="" Group="TEST" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
<pnp:FieldRefs>
<pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Required="true" />
<pnp:FieldRef ID="b280c2fa-7aba-40a2-8d9a-e2e23984c305" Name="TestField" />
</pnp:FieldRefs>
</pnp:ContentType>
</pnp:ContentTypes>
</pnp:ProvisioningTemplate>
</pnp:Templates>
</pnp:Provisioning>
Observed Behavior
Exception is thrown: Apply-PnPProvisioningTemplate : Value cannot be null. Parameter name: s At line:1 char:1
- Apply-PnPProvisioningTemplate -Path $path
-
+ CategoryInfo : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.Site.ApplyProvisioningTemplate
Steps to Reproduce
Deployment of PnP Template with CT definition. Attached sample can be used.
Thanks for your contribution! Sharing is caring.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Thx @siata13 for reporting this. This seems to be a breaking change in the server side, which we are now actively investigating. Here's a duplicate entry in the PnP Sites Core and in the PnP PowerShell repositories for this one for tracking purposes. I also changed the title to be more descriptive with the oob capabilities as this is not about the PnP wrapper.
In short - there seems to be a breaking change in the oob CSOM for handling content types in server side.
- https://github.com/SharePoint/PnP-Sites-Core/issues/2240
- https://github.com/SharePoint/PnP-PowerShell/issues/2087
All repro steps also without PnP template are more than welcome in the tenants which have the issue... if you have possibility to test things with native CSOM and without the template. This will rule out root cause options. Thanks for any further details advance.
We've logged a ticket with our tenant for the exact same error description. Debugging in Pnp Sites core I managed to track this down to the fields being reordered on the content type.
When I disabled this on creation & update, the provisioning code works fine.
You get an "Unexpected error" when doing this in the browser as well, so it does not seem to be PnP specific.
Note that not every pnp provisioned content type update would trigger this error because the fields may already be in the right order.
I've tried to just add the content type with PnP PowerShell, but was NOT able to reproduce it that way. So no error occurs. While with the template it still fails.
$documentCT = Get-PnPContentType -Identity "Document"
Add-PnPContentType -ContentTypeId "0x0100FA46988B78C6438D9F618CCDCA592331" -Group "MyFirstContentTypeGroup" -Name "MyFirstContentType" -Description "My description"
When looking at the sample in SharePoint/PnP-Sites-Core#2240 there's no reordering in my opinion.
I can confirm that CSOM works as expected, this is the issue in PnP.
Sorry guys, I've made some more tests on content type deployment and faced the same error message from native CSOM API (outside PnP Sites Core). So, it looks like the issue is somewhere in SharePoint's backend in the content type fields reordering section.
@vladivanovrf do you have an example of your tests?
I've also tested the following (PowerShell) code and it works as expected. What am I missing?
$ctx = Get-PnPContext
$ctCreation = New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
$ctCreation.Id = "0x0100FA46988B78C6438D9F618CCDCA592333"
$ctCreation.Name = "MyFirstContentType"
$ctCreation.Description = "My description"
$ctCreation.Group = "MyFirstContentTypeGroup"
$ctx.Site.RootWeb.ContentTypes.Add($ctCreation)
$ctx.ExecuteQuery()
We just confirmed this to be a change on the server side APIs related on the field reorder, like also mentioned above by @cverhelst and @vladivanovrf. It's caused by a situation where you execute the fields reorder without any fields for a content type. Recent change in server side API did not take this into account and unfortunately PnP provisioning engine will call the reorder for fields in a content type regardless if there are any.
We are working now on two sides:
- New PnP Sites Core CSOM assembly will be released today (ETA few hours) which will do the workaround for skipping the ReOrder call for content type when there's no fields. This will address the issue from PnP provisioning engine perspective in upcoming hours.
- We have internal threads moving on addressing the server side API change to include a checkup for the fields, which will be addressed in server side code. Getting that changed deployed worldwide will take much longer after the requested change has been approved, but will update this thread on the progress as have any.
Thanks everyone for sharing your test results and insights on the repro. These helped us to move forward on providing initial fix as fast as in few hours after identifying the root cause.
Root cause of the issue - if you execute following code, you will get the same exception:
ContentType.FieldLinks.Reorder(new string[] { });
@VesaJuvonen to be 100% clear, will there also be an update available of the PnP PowerShell module then, including the updated PnP Sites Core?
@advdberg - Yes - We are working on providing update for PnP Sites Core NuGet and for PnP PowerShell as a quick workaround. Basically we change those modules to be aware of this underlying issue, so if you use the PnP wrappers, you will not be impacted.
I have three tenants, one gives the exception, two other don't. I assume Microsoft is rolling out update gradually, so i will expert this issue to be present on all tenants shortly.
Our production environment is impacted due to this issue and we are not able to provision the new sites via PnP provisioning. Please suggest:
- Do we need to update PnP Powershell module in our code to get this working
- By when this fix will be available
Thanks, Rakhi Jain
Our production environment is impacted due to this issue and we are not able to provision the new sites via PnP provisioning. Please suggest:
- Do we need to update PnP Powershell module in our code to get this working
- By when this fix will be available
Thanks, Rakhi Jain
Like the Post from @VesaJuvonen it seem to be, that we must update the pnp.core assembly and the fix will be available in a few hour.
@VesaJuvonen
It's caused by a situation where you execute the fields reorder without any fields for a content type.
Not certain you mean to say this scenario was the only one causing this issue, but I (and others) experienced this issue in the browser when trying to move any field on any content type, as well as using CSOM with any input to the .Reorder() function on the FieldLinks property of a content type.
Just to make sure you're aware this was not exclusive to calling .Reorder() with an empty array.
Hi all, to note I am having the exact same issue. Provisioning scripts that use to work are now failing. For me this happens when the provisioning engine attempts to add a site column to a custom content type. This is on the latest version of PNP Powershell (version 3.9.1905.0) but the tenant is not first release.
Interestingly when running the apply pnp-provision it does actually put the content types in, (even though it errors). So if you re-run the command sufficient times, eventually the template is successfully applied.
Thx @cverhelst for the additional test details. It is indeed reproducible from the _layouts/15/ManageContentType.aspx user interface, which clearly shows that it's a server side API issue.
We are actively working on this internally, but if anyone has Premier support, please do open up a case to ensure that we get the scale of the issue identified and situation fixed as soon as possible.
We are looking into ways to reduce the impact of this issue by potentially providing a workaround fixes through PnP CSOM NuGet package and PnP PowerShell, but we can't fix the root cause directly, as fast ans the PnP components, as it's in the server side APIs. Root cause fixes are being also investigated and worked on, but timeline is still unclear.
@mag210 - PnP provisioning engine uses oob CSOM and when you add a site column to content type, it uses the Reorder method, which is then causing your operation to fail. Issue is NOT in the PnP engine, it's in the server side APIs as issue can be reproduced also using native CSOM or using UI in this case.
There's no ETA for resolving this fix for now. Please do open a Premier Support issue if you need to have updated status asap. We will keep on updating this thread also as soon as we have any updates.
Hi @VesaJuvonen I had the same findings are yours. Means breaking change on ootb api. The problem is that now you plan to release a fix in the pnp nugget or powershell packages. That's find if we can upgrade to this package version.
On our side, we do not think a breaking changes should occured in a ootb api. If a breaking changes is pushed, then you should think about creating versioning endpoint for this api to keep them both working.
We are currently in progress for releasing updated PnP Sites Core NuGet (provisioning engine) and PnP PowerShell to provide a short term workaround for addressing the server side issue. New versions will skip the Reorder call to ensure that normal provisioning scenarios will work as expected.
That can cause minimal changes on the usage of the engine, but it will also ensure that the basic scenarios are working as expected even before the server side API fixes are completed and rolled out.
@patrick-blanc - 100% agree that breaking changes should not be done in server side APIs and we are working on rolling this change back. This was caused by a human mistake and absolutely agree that we should ensure that both are working without these kind of issues in future. This is not intended situation and we are ONLY providing updated NuGet and PnP PowerShell cmdlets to help to reduce the impact of the server side API issue, until that has been fully fixed.