user3649225
user3649225

Reputation: 43

Get-PnPListItem : Object reference not set to an instance of an object

We sometimes see these errors when running via an Azure Function (only sometimes, not always).

The module is imported using:

Import-Module "D:\home\site\wwwroot\modules\SharePointPnPPowerShellOnline.psd1" -Global;

(same response without the -Global).

Use of Get-PnPListItem is:

Get-PnPListItem -List "$ListName" -Web $requestWeb

Where $requestWeb comes from Get-PnPWeb

The actual error thrown is:

Get-PnPListItem : Object reference not set to an instance of an object. at test.ps1: line 35 + Get-PnPListItem + _______________ + CategoryInfo : WriteError: (:) [Get-PnPListItem], NullReferenceException + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Lists.GetListItem

We use the 64 bit version of .Net in the Azure Function.

Has anyone else seen this? It may possibly be due to an interaction with another Azure Function running at the same time, or two instances of the same Function.

Upvotes: 1

Views: 3573

Answers (1)

Matthew McDermott
Matthew McDermott

Reputation: 652

I just ran into this with my list. Slightly different case but it may be a solution for you.

Use the list display name not the internal name. So in my case:

$listName = "InternalName"
$list = Get-PnPList -Identity $listName
#or
$items = Get-PnPListItem -List $listName -Query $query -PageSize 10

Fails

$listName = "Display Name"
$list = Get-PnPList -Identity $listName
#or
$items = Get-PnPListItem -List $listName -Query $query -PageSize 10

Works

Upvotes: 1

Related Questions