Error when using batch with Add-PNPListItem
Reporting an Issue or Missing Feature
When using the -Batch switch off Add-PnPListItem I'm getting an error. It works fine when removing the batch option and works fine using -Batch on Set-PnPListItem
Expected behavior
Create a simple hash table for adding to a SPO list:
Name Value
HR_REP_MAIL [email protected] HIRE_DT 5/10/2021 FULL_PART_TIME F REP_NAME Doe, John AC_BUSINESS_UNIT 99999999 MANAGER N BARG_UNIT N POSITION_NBR 99999999 SERVICE_DT 5/10/2021 WIN_HRBP_ID e9999999 STATE_WORK NC DEPT_DESCR Kinetic LOCATION V188 AC_SOA 0 LOCATION_DESCR Virtual Office NC Title e999999
Use this to try and add a list item via batch:
Add-PnPListItem -List 'HRData' -Values $CreationHash -Batch $Batch
Actual behavior
A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
What is the version of the Cmdlet module you are running?
1.5.0
Which operating system/environment are you running PnP PowerShell on?
- [ X] Windows
- [ ] Linux
- [ ] MacOS
- [ ] Azure Cloud Shell
- [ ] Azure Functions
- [ ] Other : please specify
Error (truncated for readability):
Exception :
Type : System.Text.Json.JsonException
Path : $.Members.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.OverloadDefinitions
Message : A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
Name : ThrowJsonException_SerializerCycleDetected
DeclaringType : System.Text.Json.ThrowHelper, System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
StackTrace : at System.Text.Json.ThrowHelper.ThrowJsonException_SerializerCycleDetected(Int32 maxDepth)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteCore[TValue](JsonConverter jsonConverter, Utf8JsonWriter writer, TValue& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, Type inputType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue& value, Type inputType, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize(Object value, Type inputType, JsonSerializerOptions options)
at PnP.Core.Model.SharePoint.ListItem.<.ctor>b__2_2(Dictionary2 keyValuePairs)
at PnP.Core.Model.BaseDataModel1.AddBatchAsync(Batch batch, Dictionary2 keyValuePairs)
at PnP.Core.Model.SharePoint.ListItemCollection.AddBatchAsync(Batch batch, Dictionary2 values, String folderPath, FileSystemObjectType fileSystemObjectType)
at PnP.Core.Model.SharePoint.ListItemCollection.AddBatch(Batch batch, Dictionary2 values, String folderPath, FileSystemObjectType fileSystemObjectType)
at PnP.PowerShell.Commands.Lists.AddListItem.ExecuteCmdlet() in c:\PnPPowerShell\src\Commands\Lists\AddListItem.cs:line 125
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\PnPPowerShell\src\Commands\Base\PnPSharePointCmdlet.cs:line 91
I have a related issue, but it behaves a little bit differently. Still, I believe, the cause of the issue is the same - something happens in the Serialization behind the scenes, .NET Core?
To reproduce my scenario do following Set up a simple list "simple_list" with Choice column "choice_col", allow multiple choices.
Then run following
Set-PnPListItem -List 'simple_list' -Identity 1 -Values @{choice_col=@("one", "two")} -Batch $batch
It will result in
A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth
is larger than the maximum allowed depth of 0
Then remove the Batch, and will work:
Set-PnPListItem -List 'simple_list' -Identity 1 -Values @{choice_col=@("one", "two")}
@gautamdsheth / @erwinvanhunen
I can't reproduce the exact errors above, however I get the following when trying to use -batch with the Set-PnPListItem
A node of type 'StartArray' was read from the JSON reader when trying to read a value of a property; however, a 'PrimitiveValue' or 'StartObject' node was expected. with a ResponseCode: 400
Might need to transfer the issue?
While the first two errors are both similar in verbiage describing circular references.
A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 0
The third one seems quite a bit different, so not sure if they are all related but they DO all happen with -Batch it seems. I'll say I was using Powershell 7.1, so the Core files were being called instead of the Framework ones. Not sure if it was the same for the other errors described here?
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days
@JAK1047 - Please try with the -nightly tomorrow, or reopen if the issue persists. Thank you.
I'm also having this issue and have tried the nightly version without any luck.
Hi, I'am facing this issue too with latest version 1.7.0 Workaround via Graph might do the job: https://michalsacewicz.com/add-items-to-a-sharepoint-list-with-powershell-pnp-vs-batch-requests-to-graph/
I'm getting the same issue
I had the same issue when using -batch I was able to get it work when using a string. Seperate choices with ;#
example: $ownerUnits = "Choice1;#Choice2"
or if you have an array with strings: $ownerUnits -join ";#"