Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetSiteCollectionAdminsAsync - NullReferenceException in CSOMResponseHelper.ProcessResponse<Site> #877

Closed
1 task done
Sean-LM opened this issue Jun 9, 2022 · 2 comments
Assignees
Labels
area:admin 📜 Admin library related bug Something isn't working

Comments

@Sean-LM
Copy link

Sean-LM commented Jun 9, 2022

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); }

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.

  1. Execute code, such as: var admins = await context.GetSiteCollectionManager().GetSiteCollectionAdminsAsync("site url");
  2. Observe NullReferenceException thrown by the SPGuidConverter

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.

@jansenbe jansenbe self-assigned this Jun 9, 2022
@jansenbe jansenbe added bug Something isn't working area:admin 📜 Admin library related labels Jun 9, 2022
@jansenbe
Copy link
Contributor

@Sean-LM : thanks for the detailed error report, this makes fixing things much easier 👍

I've pushed a fix to make the GUID parsing more reliable, this should help with your issue. Please give this a try with the next nightly build (version 1.6.74 or higher) and if things still not work, then please re-open this issue or create a new one.

Thanks for using PnP Core SDK and providing feedback.

@Sean-LM
Copy link
Author

Sean-LM commented Jun 14, 2022

Thanks so much - all seems to be in order now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:admin 📜 Admin library related bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants