Pnp-powershell: Add-PnPClientSideWebPart : adding List webpart fails with "Object reference not set to an instance of an object error".

Created on 28 Sep 2020  路  5Comments  路  Source: pnp/PnP-PowerShell

Reporting an Issue or Missing Feature

When using Add-PnPClientSideWebPart to add a List webpart to a page, it fails and display a _Object reference not set to an instance of an object_ error.

Expected behavior

List WebPart should be added to the client side page.

Actual behavior

Webpart is not added to the page and the command fails with _Object reference not set to an instance of an object_ error.

Here's the output of my real script :

Add-PnPClientSideWebPart : Object reference not set to an instance of an object.
At Line 1, char:1
+ Add-PnPClientSideWebPart -Page $testPage -Section 1 -Order 1 -Column  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Add-PnPClientSideWebPart], NullReferenceException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.WebParts.AddClientSideWebPart

Steps to reproduce behavior

Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/example-site
$web = Get-PnPWeb
$documentsList = Get-PnPList -Identity Documents -Includes DefaultView
$testPage = Add-PnPClientSidePage -Name TestPage -LayoutType Article -CommentsEnabled:$false -Publish -HeaderLayoutType NoImage -PromoteAs None
Add-PnPClientSidePageSection -Page $testPage -SectionTemplate OneColumn -Order 1 -ZoneEmphasis 0

$webPartProperties  = @{"selectedListId" = "$($documentsList.Id)";"selectedListUrl" = "$($documentsList.RootFolder.ServerRelativeUrl)";"webRelativeListUrl" = "$($documentsList.RootFolder.ServerRelativeUrl -ireplace $web.ServerRelativeUrl,"""")";"selectedViewId" = "$($documentsList.DefaultView.Id)";"webpartHeightKey" = 1;"isDocumentLibrary" = $true}
Add-PnPClientSideWebPart -Page $testPage -Section 1 -Order 1 -Column 1 -DefaultWebPartType List -WebPartProperties $webPartProperties

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [ ] PnP PowerShell for SharePoint 2019
  • [x] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

3.25.2009.1 (quickly tried the last "known" working version in production environment
which was 3.18.2002.0, but also fails)

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means
bug

Most helpful comment

The root cause of the problem has been found and a fix is rolling out soon.

All 5 comments

Client Web Part Issue
Am also getting the same issue. Please help us.

same for us, looks like not related to pnp engine (we have not upgraded it for almost a year); on our tenant the issue started this week, all our newly provisioned pages are missing list webparts - ughh

Same problem for us. We developed a new experience for our colleagues, and now it is not working anymore with the same error.

The root cause of the problem has been found and a fix is rolling out soon.

Think we can close, there's many independent confirmations the issue is fixed

Was this page helpful?
0 / 5 - 0 ratings