SharePoint 2016 – PnP ApplyProvisioningTemplate – Error: Value cannot be null. Parameter name: input

Over the last few weeks I’ve been working with one of my customers to create sites from a site request list. For each new client that they register a new site request is created and then a SharePoint Designer workflow calls a service that will create a site collection and then after that a PnP template is applied.

Error: Value cannot be null. Parameter name: input

All quite easy stuff, however today I ran into a problem. I got the following error when a workflow was added to my site:

Error: Value cannot be null. Parameter name: input

When I tried to apply the templates using PnP PowerShell the template would simply work. So my templates are valid.

After a bit of debugging I found that the following lines in PnP Sites core’s objectWorkflows.cs are responsible for reading the workflow definition file:

// Load the Workflow Definition XAML
Stream xamlStream = template.Connector.GetFileStream(templateDefinition.XamlPath);
XElement xaml = XElement.Load(xamlStream);

The templateDefinition.XamlPath just contains the guid.xaml file name without any location

In this case I didn’t really want to add the path to my template xml file as that would be complicated to pass down to the pice of code that is running. Quite early on in the process the template is read and after that the file location is not relevant anymore.

SharePoint 2016 - PnP ApplyProvisioningTemplate - Error: Value cannot be null. Parameter name: input

What to do next?

Within my web service I’m running:

web.ApplyProvisioningTemplate(template, provisioningTemplateApplyingInformation);

I’m simply changing my current directory to  the template file and now the PnP Sites Core libraries pick up my Workflow file:

System.IO.Directory.SetCurrentDirectory(FillPathToTemplateFile);
web.ApplyProvisioningTemplate(template, provisioningTemplateApplyingInformation);

Why does this work with PnP PowerShell?

Within the PnP PowerShell code your path is adjusted while PnP-ProvisioningTemplate is running. This makes it possible to find the workflow file.


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading