-
Notifications
You must be signed in to change notification settings - Fork 217
Description
Category
- Bug
Describe the bug
In one of my tenants, calling SiteCollectionManager.GetSiteCollectionAdminsAsync throws a NullReferenceException, from debugging within the PnP code, I've narrowed it down (I believe) to the deserialization of a Site object in this stack trace:
at PnP.Core.Test.Services.Core.CSOM.Utils.CustomConverters.SPGuidConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) in /_/src/sdk/PnP.Core/Services/Core/CSOM/Utils/CustomConverters/SPGuidConverter.cs:line 11
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at PnP.Core.Services.Core.CSOM.Utils.CSOMResponseHelper.ProcessResponse[T](String response, Int64 propertyIdentifier) in /_/src/sdk/PnP.Core/Services/Core/CSOM/Utils/CSOMResponseHelper.cs:line 17
at PnP.Core.Admin.Services.Core.CSOM.Requests.Tenant.GetSiteByUrlRequest.ProcessResponse(String response) in /_/src/sdk/PnP.Core.Admin/Services/Core/CSOM/Requests/Tenant/GetSiteByUrlRequest.cs:line 235
at PnP.Core.Services.BatchClient.ProcessCsomBatchResponse(CsomBatch csomBatch, String batchResponse, HttpStatusCode statusCode) in /_/src/sdk/PnP.Core/Services/Core/BatchClient.cs:line 2313
at PnP.Core.Services.BatchClient.ExecuteCsomBatchAsync(Batch batch) in /_/src/sdk/PnP.Core/Services/Core/BatchClient.cs:line 2243
at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch) in /_/src/sdk/PnP.Core/Services/Core/BatchClient.cs:line 350
at PnP.Core.Model.BaseDataModel`1.RequestAsync(ApiCall apiCall, HttpMethod method, String operationName) in /_/src/sdk/PnP.Core/Model/Base/BaseDataModel.cs:line 965
at PnP.Core.Model.BaseDataModel`1.RawRequestAsync(ApiCall apiCall, HttpMethod method, String operationName) in /_/src/sdk/PnP.Core/Model/Base/BaseDataModel.cs:line 1021
at PnP.Core.Admin.Model.SharePoint.SiteCollectionManagement.GetSiteCollectionAdminsAsync(PnPContext context, Uri siteUrl, VanityUrlOptions vanityUrlOptions) in /_/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/SiteCollectionManagement.cs:line 273
at PnP.Core.Admin.Model.SharePoint.SiteCollectionManager.GetSiteCollectionAdminsAsync(Uri site, VanityUrlOptions vanityUrlOptions) in /_/src/sdk/PnP.Core.Admin/Model/SharePoint/Core/Internal/SiteCollectionManager.cs:line 189
viewing the raw JSON, I believe this is the cause, the API returns: "SensitivityLabelId": null, and the deserializer expects to be able to deserialize this into a guid:
| public Guid SensitivityLabelId { get => GetValue<Guid>(); set => SetValue(value); } |
pnpcore/src/sdk/PnP.Core/Services/Core/CSOM/Utils/CustomConverters/SPGuidConverter.cs
Line 11 in 2f54c02
| string value = reader.GetString(); |
In my other tenant, this does not occur, and I'm not sure why. All of the other Guid-typed properties return "\\/Guid(00000000-0000-0000-0000-000000000000)\\/" (or an actual guid), which the deserializer is able to handle. I think SPGuidConverter needs to be able to handle null values (and just deserialize them to empty guid.)
Steps to reproduce
(I'm not sure the exact tenant configuration that causes this - one of my tenants does not encounter this, but the other one encounters it on many/most sites that I try to process. I do not have access to the SP admin console to check again settings.) - The absence of a sensitivity label on the site might be the cause? We have no sensitivity labels configured in this tenant.
- Execute code, such as:
var admins = await context.GetSiteCollectionManager().GetSiteCollectionAdminsAsync("site url"); - Observe
NullReferenceExceptionthrown by theSPGuidConverter
Expected behavior
Call to GetSiteCollectionAdminsAsync succeeds.
Environment details (development & target environment)
- SDK version: 1.6.72-nightly and also 1.6.28-nightly
- OS: Windows 10
- SDK used in: Console App
- Framework: .net 6
- Browser(s): n/a
- Tooling: VS Code
- Additional details:
Additional context
n/a
Thanks for your contribution! Sharing is caring.