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.

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:

[code lang=text]
// 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 Microsoft 365

What to do next?

Within my web service I’m running:

[code lang=text]
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:

[code lang=text]
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.





Leave a Reply

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

%d bloggers like this: