Pnp-sites-core: Apply-PnPProvisioningTemplate : Index was out of range. Must be non-negative and less than the size of the collection.

Created on 4 Jan 2020  路  9Comments  路  Source: pnp/PnP-Sites-Core

Category

[x] Bug
[ ] Enhancement

Environment

[x] Office 365 / SharePoint Online
[ ] SharePoint 2016
[ ] SharePoint 2013

If SharePoint on-premises, what's exact CU version:

Expected or Desired Behavior

Field is added to a content type that already possesses 53 fields

Observed Behavior

Attempting to add a field with the following fails:

    <pnp:ContentType ID="0x010065F13FF729926C4E81346145EC49CCC6" Name="Correspondent" Description="" Group="_Case Management Content Types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
      <pnp:FieldRefs>
        <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Required="true" />
        <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" />
        <pnp:FieldRef ID="19a21566-9ebc-4dd1-9538-d231f32a393f" Name="DetailCache" />
        <pnp:FieldRef ID="9c440d2a-721a-4e5d-b671-9a832552bca2" Name="Salutation"/>
        <pnp:FieldRef ID="6e68803b-8805-45e6-9750-124ab49b0786" Name="HonorificPrefix" />
        <pnp:FieldRef ID="4a722dd4-d406-4356-93f9-2550b8f50dd0" Name="FirstName" />
        <pnp:FieldRef ID="61a7b89a-cc30-4585-87c7-5cde6ff49e5a" Name="FamilyName" />
        <pnp:FieldRef ID="0ef09b79-62d7-4b9c-a974-4b95c6bbc38d" Name="HonorificSuffix" />
        <pnp:FieldRef ID="2192dba5-5ce3-42b7-8d16-5843d5e4c7a2" Name="CorrespondentGender" />
        <pnp:FieldRef ID="475c2610-c157-4b91-9e2d-6855031b3538" Name="FullName" />
        <pnp:FieldRef ID="9a631556-3dac-49db-8d2f-fb033b0fdc24" Name="WorkZip" />
        <pnp:FieldRef ID="6a21db32-0509-4648-8c28-32d175ab89f1" Name="CorrespondentFlags" />
        <pnp:FieldRef ID="38f156a9-db03-4400-a89b-bc40869eaf46" Name="Position" />
        <pnp:FieldRef ID="2c700906-b88f-4cba-aa8e-fd66f12f8231" Name="Organisation" />
        <pnp:FieldRef ID="64cd368d-2f95-4bfc-a1f9-8d4324ecb007" Name="StartDate" />
        <pnp:FieldRef ID="abca75de-75de-4ab1-811b-8853f799982b" Name="CorrespondentEndDate" />
        <pnp:FieldRef ID="fc2e188e-ba91-48c9-9dd3-16431afddd50" Name="WorkAddress" />
        <pnp:FieldRef ID="6ca7bd7f-b490-402e-af1b-2813cf087b1e" Name="WorkCity" />
        <pnp:FieldRef ID="b09ecd4c-8fca-4c13-9d60-cba24eb6b41a" Name="County" />
        <pnp:FieldRef ID="d69bcc0e-57c3-4f3b-bbc5-b090edf21f0f" Name="PrimaryNumber" />
        <pnp:FieldRef ID="3f3a5c85-9d5a-4663-b925-8b68a678ea3a" Name="WorkCountry" />
        <pnp:FieldRef ID="488baae0-1883-4d3e-967a-9d4112f6bccf" Name="Constituency" />
        <pnp:FieldRef ID="e244246e-26e9-4645-94ba-e92d98018697" Name="IsPMConstituency" />
        <pnp:FieldRef ID="fce16b4c-fe53-4793-aaab-b4892e736d15" Name="EMail" />
        <pnp:FieldRef ID="2a464df1-44c1-4851-949d-fcd270f0ccf2" Name="CellPhone" />
        <pnp:FieldRef ID="9d1cacc8-f452-4bc1-a751-050595ad96e1" Name="WorkFax" />
        <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" />
        <pnp:FieldRef ID="9da88795-3bc2-4381-b133-56997eb48a2f" Name="CommunicationPreference" />
        <pnp:FieldRef ID="52d68a54-088a-4f31-b226-4e75716a2225" Name="Bio"/>
        <pnp:FieldRef ID="3f542d2b-9fd5-4201-9a12-170f776365c6" Name="Details"/>
        <pnp:FieldRef ID="f42f847b-e32f-49bd-8326-04b99fa2ef7c" Name="SpecialInstructions" />
        <pnp:FieldRef ID="519da271-9a77-4913-9164-533428dfd2c8" Name="TotalCases" />
        <pnp:FieldRef ID="345fa037-2e98-4d8d-a6c8-47bf0297ee44" Name="PoliticalParty" />
        <pnp:FieldRef ID="6367e533-6927-4570-8c24-24286e8d942f" Name="IsBusiness" />
        <pnp:FieldRef ID="94dae73e-45e7-403d-a625-1433952e4121" Name="IsCentre" />
        <pnp:FieldRef ID="af222961-d65e-4a58-92c6-b4f27d6867d0" Name="IsCharity" />
        <pnp:FieldRef ID="b025882b-09bc-44e9-ae08-c7053245d595" Name="IsChild" />
        <pnp:FieldRef ID="7f27f246-637f-44a6-90e1-adfadf69cd73" Name="IsCondolences" />
        <pnp:FieldRef ID="a72fa7f4-fe85-4e12-b3dc-320279160b63" Name="IsDeceased" />
        <pnp:FieldRef ID="fb4d42a7-f324-47aa-b407-7c420a54027b" Name="IsEventsVisits" />
        <pnp:FieldRef ID="5c55660c-9096-4357-96bd-b24620c5518c" Name="IsKnownToPM" />
        <pnp:FieldRef ID="d6cdf95d-5bf0-45d1-9378-d8d87ec4a941" Name="IsMP" />
        <pnp:FieldRef ID="33736c48-1e0c-46f9-8eb7-c2d52f465668" Name="IsMSP_MWA_MNIDA" />
        <pnp:FieldRef ID="afeccd8d-9e74-4329-9e43-d4ff6ebd723a" Name="IsPeer" />
        <pnp:FieldRef ID="e52db44f-5073-4540-97b4-54b5ed988e2a" Name="IsPersistent" />
        <pnp:FieldRef ID="70f781b1-3d8a-4158-960e-c2028c8ed59f" Name="IsPolitical" />
        <pnp:FieldRef ID="5c34b060-b580-43ba-8142-814f4ec6540b" Name="IsPrisoner" />
        <pnp:FieldRef ID="6c061e00-daeb-427d-bc17-96a1429af6dc" Name="IsPublic" />
        <pnp:FieldRef ID="e6f9d004-31ab-49c3-9af4-edf744f98ca9" Name="IsSchool" />
        <pnp:FieldRef ID="918a3101-cc9b-4e5e-b218-86c59b4dc7ed" Name="InsertedOn" />
        <pnp:FieldRef ID="1e676c28-5396-410c-80a0-ec59d33fbc83" Name="InsertedBy" />
        <pnp:FieldRef ID="c7966cf2-e8e3-44d2-8fd3-d04e69f0236c" Name="UpdatedOn" />
        <pnp:FieldRef ID="3d7f3fa0-591e-4c2a-98cd-cef60c860e73" Name="UpdatedBy" />
        <pnp:FieldRef ID="e5df4fd2-0141-4f38-b7f8-978d1ab639a2" Name="RetiredOn" />
        <pnp:FieldRef ID="f7866d61-dd4f-45c2-835b-3db3be5295ba" Name="RetiredBy" />
      </pnp:FieldRefs>
    </pnp:ContentType>

Steps to Reproduce

  • Create a content type with 52 fields attached
  • Use similar XML in a PnP Provisioning template as above to add an additional one
Needs

Most helpful comment

after some digging we found something, it looks like the (base) language of the site is causing this issue.

Notify the difference in the FieldRef Name attribute.

This fails with the 'index out of range' error:

<pnp:ContentType ID="0x0100D3A8592F54F0EB4E9F116D6CDAD26020" Name="SiteInfo" Description="" Group="Custom content types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
          <pnp:FieldRefs>            
            <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" UpdateChildren="true" />
            <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Hidden="true" UpdateChildren="true" />
          </pnp:FieldRefs>
        </pnp:ContentType>

This works fine:

<pnp:ContentType ID="0x0100D3A8592F54F0EB4E9F116D6CDAD26020" Name="SiteInfo" Description="" Group="Custom content types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
          <pnp:FieldRefs>            
            <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="Content type" UpdateChildren="true" />
            <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Titel" Hidden="true" UpdateChildren="true" />
          </pnp:FieldRefs>
        </pnp:ContentType>

All 9 comments

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

Seeing the same issue with a 201909 schema and PnP PowerShell version 3.17.2001.2, changing it back to 201903 in the tempalte fixes the isue on our side

Seeing the same issue with a 201909 schema and PnP PowerShell version 3.17.2001.2, changing it back to 201903 in the tempalte fixes the isue on our side

Also seeing this error with the same version, but using an older schema doesn't fix the issue for us. Nothing really shown in the debug logs but the last log entry before the execution ending is Update child Content Types: True

I also had this problem. In my case, I had a list with data using the affected content type. It was a dev environment, so I could delete the list and after that provisioning the content type without problems. I've not been able though, to identify which field or fields are provoking the issue and why. Maybe because some required field not being populated?

I have the same issue
Apply-PnPProvisioningTemplate : Index was out of range. Must be non-negative and less than the size of the collection.

When I'm appying the template for the 2nd time on the same site it runs without errors!

Tested with schema: 2019/03 and 2019/09 using version: 3.17.2001.2

Is there any news on this issue ?

We now see the following while we experience this error on applying a template to a (modern) site:

  1. The trace logs of the template succeed without logged errors, but the error is shown in PowerShell
  2. Excluding the Contenttype handler doesn't show the 'index was out of range' error

Fails:
$result = Apply-PnPProvisioningTemplate -Path "C:\folder\ModernTemplate.xml" -Connection $connectionPnP
Error =
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
At line:1 char:11
$result = Apply-PnPProvisioningTemplate -Path C:\folder ...
~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.Site.ApplyProvisioningTemplate

Succeeds:
$result = Apply-PnPProvisioningTemplate -Path "C:\folder\ModernTemplate.xml" -Connection $connectionPnP -ExcludeHandlers ContentTypes

Does anyone know how to get more logging/pointing in the right direction?
@jansenbe @PaoloPia

No but I now have a work around.

Split the provisioning into 'chunks' of less than 50, the default number of fields returned by a query and it will work:

<pnp:ContentType ID="0x010065F13FF729926C4E81346145EC49CCC6" Name="Correspondent" Description="" Group="_Case Management Content Types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
      <pnp:FieldRefs>
        <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Required="true" />
        <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" />
... More field refs but less than 50
/>
<pnp:ContentType ID="0x010065F13FF729926C4E81346145EC49CCC6" Name="Correspondent" Description="" Group="_Case Management Content Types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
      <pnp:FieldRefs>
        <pnp:FieldRef ID="475c2610-c157-4b91-9e2d-6855031b3538" Name="FullName" />
... More field refs but less than 50
      </pnp:FieldRefs>
    </pnp:ContentType>

after some digging we found something, it looks like the (base) language of the site is causing this issue.

Notify the difference in the FieldRef Name attribute.

This fails with the 'index out of range' error:

<pnp:ContentType ID="0x0100D3A8592F54F0EB4E9F116D6CDAD26020" Name="SiteInfo" Description="" Group="Custom content types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
          <pnp:FieldRefs>            
            <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" UpdateChildren="true" />
            <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Hidden="true" UpdateChildren="true" />
          </pnp:FieldRefs>
        </pnp:ContentType>

This works fine:

<pnp:ContentType ID="0x0100D3A8592F54F0EB4E9F116D6CDAD26020" Name="SiteInfo" Description="" Group="Custom content types" NewFormUrl="" EditFormUrl="" DisplayFormUrl="">
          <pnp:FieldRefs>            
            <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="Content type" UpdateChildren="true" />
            <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Titel" Hidden="true" UpdateChildren="true" />
          </pnp:FieldRefs>
        </pnp:ContentType>
Was this page helpful?
0 / 5 - 0 ratings