pnp / pnpframework

PnP Framework is a .NET library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions
https://pnp.github.io/pnpframework/
MIT License
204 stars 141 forks source link

invoke-pnpsitetemplate : Object reference not set to an instance of an object #512

Open KaushalKhamar opened 2 years ago

KaushalKhamar commented 2 years ago

I am trying to apply site template using invoke-PnPSiteTemplate command in group site but getting error of Object reference not set to an instance of an object

below is error

Message          : Object reference not set to an instance of an object.
Stacktrace       :    at Microsoft.SharePoint.Client.FieldAndContentTypeExtensions.BestMatch(String contentTypeId, IEnumerable`1 contentTypeCollection)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.CreateView(Web web, View view, ViewCollection existingViews, List createdList, 
                   PnPMonitoredScope monitoredScope, TokenParser parser, Int32 currentViewIndex, Int32 total)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.ProcessViews(Web web, TokenParser parser, PnPMonitoredScope scope, ListInfo 
                   listInfo)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, 
                   ProvisioningTemplateApplyingInformation applyingInformation)
                      at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, 
                   ProvisioningTemplateApplyingInformation provisioningInfo, Boolean calledFromHierarchy, TokenParser tokenParser)
                      at PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.ExecuteCmdlet()
                      at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
SuperKLA commented 1 month ago

Hello, I can confirm this issue. I tested the code and found the following. image

parameter: contentTypeId, "0x01" parameter: contentTypeCollection, default contenttype collection of a SPlist

In the first iteration, CountCommonBytes results with commonBytes = 0. Therefore first if is false, program runs into the next if. There bestMatch value is null and thats the reason, why we get a Object reference not set.

@KaushalKhamar If you really need this function, copy paste it and fix it for yourself.