You're importing a PnP provisioning template and it fails with:
Index was out of range. Must be non-negative and less than the size of the collection.
Just a generic .NET collection error with no useful context — no page name, no section number, no web part reference. Here's what's causing it and how to fix it.
TL;DR: This error usually means a web part is assigned to a column that doesn't exist in its section. Check for mismatches between theTypeattribute on your<pnp:Section>elements and theColumnvalues on the controls inside them.
The Cause
PnP provisioning templates store page layouts as XML. Each page is made up of sections, and each section has a defined type — OneColumn, TwoColumnLeft, TwoColumnRight, ThreeColumn, and so on.
Inside each section, web parts are positioned using a Column attribute. The problem occurs when the column a web part references doesn't exist in the section type.
The error comes from the underlying .NET collection handling inside the provisioning engine, which is why it gives no context about pages or sections — it simply tries to access a list index that doesn't exist and throws a generic failure.
For example:
<pnp:Section Order="9" Type="TwoColumnRight">
<pnp:CanvasControl ... Order="1" Column="3" />
<pnp:CanvasControl ... Order="2" Column="3" />
</pnp:Section>
A TwoColumnRight section only has two columns. These web parts are referencing Column 3, which doesn't exist — hence the error.
How It Happens
This almost always occurs when a page section layout was changed after the template was exported. The typical sequence:
- A page is built with a three-column section
- Web parts are added to all three columns
- Someone changes the section layout to two columns in the SharePoint UI
- The web parts that were in column 3 get collapsed — SharePoint handles this visually
- The template is exported — but the XML now has a
TwoColumnRightsection type with web parts still referencingColumn="3" - When you try to import that template, PnP tries to place a web part in a column that doesn't exist
The frustrating part is that the page looks fine in SharePoint. The problem only surfaces during provisioning.
How to Find It
Open your .xml template file and search for mismatches between section types and column references. The valid column numbers for each section type are:
| Section Type | Valid Columns |
|---|---|
| OneColumn | 1 |
| OneColumnFullWidth | 1 |
| TwoColumnLeft | 1, 2 |
| TwoColumnRight | 1, 2 |
| ThreeColumn | 1, 2, 3 |
Search the XML for Column="3" and check whether any of those controls sit inside a section that isn't ThreeColumn. Similarly, check for Column="2" inside OneColumn sections.
A typical offending block looks like this:
<!-- Section defined as two columns -->
<pnp:Section Order="9" Type="TwoColumnRight">
<!-- Web part referencing a third column that doesn't exist -->
<pnp:CanvasControl WebPartType="QuickLinks"
Order="1" Column="3">
...
</pnp:CanvasControl>
</pnp:Section>
The Fix
You have two options depending on what the page should actually look like:
Option 1 — Fix the section type to match reality
If the page genuinely has three columns, the section type in the XML is wrong. Change it:
<!-- Before -->
<pnp:Section Order="9" Type="TwoColumnRight">
<!-- After -->
<pnp:Section Order="9" Type="ThreeColumn">
Option 2 — Move the web parts to a valid column
If the page is genuinely two columns and the affected web parts need to move, update the Column attribute:
<!-- Before -->
<pnp:CanvasControl ... Order="1" Column="3" />
<!-- After -->
<pnp:CanvasControl ... Order="1" Column="2" />
After making the change, re-run the provisioning — the error should be gone.
Watch for Multiple Occurrences
This is rarely a one-off issue. Templates exported from sites that have evolved over time often have this mismatch in multiple sections across multiple pages. Fix one occurrence and you may hit another on the next run.
Work through the template systematically — check every section type against the column numbers used by its controls before attempting to provision.
Prevention and Validation
When exporting PnP templates from sites that have changed layout over time, a quick XML audit before importing can save a frustrating debugging session.
For larger templates, consider adding a validation step that scans for invalid column references before provisioning — a short PowerShell script that parses the XML and flags any Column value that exceeds the maximum for its parent section type. That's a much faster feedback loop than a failed provisioning run.