Skip to content

ObjectNotFound exception from long running ZervicePoint PowerShell Management commands

Problem

When executing certain time consuming commands (such as Get-ZPProcess to get all the processes in a store) you may receive an ObjectNotFound exception.

Console output typically looks like the following

PS > Get-ZPProcess

Get-ZPProcess : One or more errors occurred.
At line:1 char:1
+ Get-ZPProcess
+ ~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (:) [Get-ZPProcess], ObjectNotFoundException
    + FullyQualifiedErrorId : Zipper.ZervicePoint.WebApi.PowerShell.GetZPProcessCommand

Cause

The ZervicePoint PowerShell Management commands utilize the System.Net.Http.HttpClient class when sending requests to the ZervicePoint API Web. By default the HttpClient class waits a maximum of 100 seconds before the request times out.

To determine if this is the cause of the problem, use any of the following methods

Method 1

Directly after receiving the error, examine the $error object to find out what the inner exception is.

PS > $error[0].Exception.InnerException

A task was canceled.

If the result of the above command is "A task was canceled" then you're experiencing a timeout.

Method 2

Use the MeasureCommand command to determine how long the command runs before the exception is thrown.

PS > Measure-Command -Expression { Get-ZPProcess }

Days : 0
Hours : 0
Minutes : 1
Seconds : 40
Milliseconds : 5
Ticks : 1000057594
TotalDays : 0.00115747406712963
TotalHours : 0.0277793776111111
TotalMinutes : 1.66676265666667
TotalSeconds : 100.0057594
TotalMilliseconds : 100005.7594

If the TotalSeconds property of the returned TimeSpan object is 100 or more then you're experiencing a timeout.

Solution

To solve the issue try increasing the maximum wait time by specifying the number of seconds (or a TimeSpan object) in the -RequestTimeOut optional parameter:

PS > Get-ZProcess -RequestTimeOut 300

The above command will wait a maximum of 300 seconds (5 minutes) for the response to arrive.