Add-PnPPage broken: One of the identified items was in an invalid format.
See original GitHub issueProvisioning new client side pages using a PnP template fails with error ‘One of the identified items was in an invalid format’.
Error is reproduceable by the following steps:
- Create a new plain-vanila page in a SharePoint site.
- Export the page as PnP template using Export-PnPPage.
- Delete the page in the site.
- Try recreating the page by applying the previously exported PnP tempalte using Invoke-PnPTemplate. This will produce the error ‘One of the identified items was in an invalid format’. The page nevertheless has been created, but somehow is incomplete / non functional.
- Re-applying the template by calling Invoke-PnPTemplate again won’t change a thing.
Interestingly the template will be applied without issues, if the page already exists in the site. So currently it’s a kind of work around for me to first create the page using SharePoint GUI and then applying the template.
Please note: We don’t have that issue in all tenants, but we can now reproduce it at least in two of them.
Issues can be nailed down to the actual page creation process:
Creating a new page like this:
Add-PnPPage -Name "TEST"
Result: Add-PnPPage: One of the identified items was in an invalid format.
The underlying exception is this:
Exception :
Type : System.FormatException
TargetSite :
Name : GetGuid
DeclaringType : System.Text.Json.JsonElement
MemberType : Method
Module : System.Text.Json.dll
Message : One of the identified items was in an invalid format.
Data : System.Collections.ListDictionaryInternal
Source : System.Text.Json.Rethrowable
HResult : -2146233033
StackTrace :
at System.Text.Json.JsonElement.GetGuid()
at PnP.Core.Model.SharePoint.FieldTaxonomyValue.FromJson(JsonElement json)
at PnP.Core.Services.JsonMappingHelper.ProcessSpecialRestFieldTypeAsync(TransientObject pnpObject, String propertyName,
JsonElement json)
at PnP.Core.Services.JsonMappingHelper.FromJsonRest(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse,
Func`2 fromJsonCasting)
at PnP.Core.Services.JsonMappingHelper.FromJson(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse, Func`2
fromJsonCasting)
at PnP.Core.Model.BaseDataModel`1.ProcessResponseAsync(ApiResponse apiResponse, Expression`1[] expressions)
at PnP.Core.Services.JsonMappingHelper.FromJsonRest(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse,
Func`2 fromJsonCasting)
at PnP.Core.Services.JsonMappingHelper.FromJson(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse, Func`2
fromJsonCasting)
at PnP.Core.Services.JsonMappingHelper.MapJsonToModel(BatchRequest batchRequest)
at PnP.Core.Services.BatchClient.ProcessSharePointRestInteractiveResponse(BatchRequest restRequest, HttpStatusCode
statusCode, Dictionary`2 responseHeaders, Stream responseContent)
at PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch)
at PnP.Core.Services.BatchClient.ExecuteSharePointRestBatchAsync(Batch batch)
at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)
at PnP.Core.Model.BaseDataModel`1.BaseRetrieveAsync(ApiCall apiOverride, Func`2 fromJsonCasting, Action`1 postMappingJson,
Expression`1[] expressions)
at PnP.Core.Model.SharePoint.Web.GetFileByServerRelativeUrlAsync(String serverRelativeUrl, Expression`1[] expressions)
at PnP.Core.Model.SharePoint.Web.GetFileByServerRelativeUrlOrDefaultAsync(String serverRelativeUrl, Expression`1[]
expressions)
at PnP.Core.Model.SharePoint.Page.GetPageFileAsync(String pageName, IList pagesLibrary)
at PnP.Core.Model.SharePoint.Page.EnsurePageListItemAsync(String pageName)
at PnP.Core.Model.SharePoint.Page.SaveAsync(String pageName)
at PnP.Core.Model.SharePoint.Page.Save(String pageName)
at PnP.PowerShell.Commands.Pages.AddPage.ExecuteCmdlet() in c:\build\src\Commands\Pages\AddPage.cs:line 77
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPSharePointCmdlet.cs:line 60
CategoryInfo : WriteError: (:) [Add-PnPPage], FormatException
FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Pages.AddPage
ErrorDetails : One of the identified items was in an invalid format.
InvocationInfo :
MyCommand : Add-PnPPage
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 16
Line : Add-PnPPage -Name "TEST"
PositionMessage : At line:1 char:1
+ Add-PnPPage -Name "TEST"
+ ~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Add-PnPPage
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
By the way - the same is (not surprisingly) true, if one tries to remove such a broken page:
Remove-PnPPage -Identity 'TEST.aspx'
Result: Remove-PnPPage: One of the identified items was in an invalid format.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top GitHub Comments
This is still an issue. Thank you @ohaak2 for the workaround. Replacing all default values in our pnp templates using -1 fixed the issue:
Calling Add-PnPPage or Invoke-PnPSiteTemplate for new pages work without issue.
We’ve now identified the reason behind our issue. It’s infact nothing tenant specifc but in our case occurs just on all intranet sites using a specific content type.
Content type was referencing a site taxonomy based site field that was configured to have a specific default value. The field definition contained a default value like this:
The fact that the id number ‘21’ here might not correlate to the correct value in the taxonomy hidden list was so far never an issue for any type of provisioning, but it seems to be now - and not just for items using the content type in question, but in fact for all items (site pages) created in the library (no matter which content type). Funny thing here is, that creating a new page using the same content type using SharePoint GUI has no issues.
Our fix is now changing the field definition like this:
Thanks to PnP PowerShell it’s quite easy to fix all sites involved using something like this: