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

Get SiteCollection properties throws ArgumentOutOfRangeException #803

Closed
1 task done
FlorianLabranche opened this issue Mar 30, 2022 · 6 comments
Closed
1 task done
Assignees
Labels
area: model 📐 Related to the core SDK models bug Something isn't working

Comments

@FlorianLabranche
Copy link

FlorianLabranche commented Mar 30, 2022

Category

  • Bug

Describe the bug

Getting site collection properties throw the following exception :

System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.

Steps to reproduce

Below code snippet can be used to repro the issue:

using var context = await pnpContextFactory.CreateAsync("SiteToWorkWith");

var siteUri = new Uri($"https://contoso.sharepoint.com/sites/MySite");
// Below line throw an exception : "System.ArgumentOutOfRangeException: 'Year, Month, and Day parameters describe an un-representable DateTime.'"
var siteProperties = await context.GetSiteCollectionManager().GetSiteCollectionPropertiesAsync(siteUri);

Environment details (development & target environment)

  • SDK version: 1.5.16-nightly and 1.5.104-nightly
  • OS: Windows 10
  • SDK used in: Console App
  • Framework: .Net 6.0
  • Browser(s): N/A
  • Tooling: Visual Studio 2022

Additional context

Related issue: #703

Fails since 28/03/2022.

Stack trace:

System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
at System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond)
at PnP.Core.Services.Core.CSOM.Utils.DateHelpers.DateConstuctorStrategy.ConverDate(String dateValue)
at PnP.Core.Services.Core.CSOM.Utils.DateHelpers.CSOMDateConverter.ConverDate(String dateValue)
at PnP.Core.Services.Core.CSOM.Utils.CustomConverters.DateTimeConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable1 actualByteCount) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 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)
at PnP.Core.Admin.Services.Core.CSOM.Requests.Tenant.GetSitePropertiesRequest.ProcessResponse(String response)
at PnP.Core.Services.BatchClient.ProcessCsomBatchResponse(CsomBatch csomBatch, String batchResponse, HttpStatusCode statusCode)
at PnP.Core.Services.BatchClient.ExecuteCsomBatchAsync(Batch batch)
at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)
at PnP.Core.Model.BaseDataModel1.RequestAsync(ApiCall apiCall, HttpMethod method, String operationName) at PnP.Core.Model.BaseDataModel1.RawRequestAsync(ApiCall apiCall, HttpMethod method, String operationName)
at PnP.Core.Admin.Model.SharePoint.SiteCollectionManagement.GetSiteCollectionPropertiesByUrlAsync(PnPContext context, Uri siteUrl, Boolean detailed)
at PnP.Core.Admin.Model.SharePoint.SiteCollectionManager.GetSiteCollectionPropertiesAsync(Uri site)
at Program.

$(String[] args) in C:\Sources\PoC\PnP.Core.Demo\PnP.Core.Demo\Program.cs:line 32

@jansenbe jansenbe self-assigned this Mar 30, 2022
@jansenbe jansenbe added question Further information is requested area: model 📐 Related to the core SDK models labels Mar 30, 2022
@jansenbe
Copy link
Contributor

jansenbe commented Apr 4, 2022

@FlorianLabranche , @Sean-LM, @TheRealDrNick: I can reproduce this issue, seems that we're getting following datetime string back: /Date(2022,2,29,9,40,58,397)/. Obviously February 29th does not exist in 2022...quite weird thing, but will add some safety measures to copy with this.

@jansenbe jansenbe added bug Something isn't working and removed question Further information is requested labels Apr 4, 2022
@jansenbe
Copy link
Contributor

jansenbe commented Apr 4, 2022

@FlorianLabranche , @Sean-LM, @TheRealDrNick: issue has been fixed and will be part of the next nightly build, version 1.6.7 or higher. Closing this issue now, feel free to re-open or create a new one when the issue is still not fixed in your setup.

@jansenbe jansenbe closed this as completed Apr 4, 2022
@FlorianLabranche
Copy link
Author

@jansenbe: Thank you for the update but I think there's an issue with the date parser.

In #703, we had a 0 for month value for a site created/modified in january.
Here, we have a 2 for month value for a site created/modified in march.

As documented here, month value MUST be in the range 0–11.

When I do a quick comparison between a call using PnPCore and CSOM, for the same site, the date from PnP call is a month before the one returned by CSOM.

So, my guess is the datetime conversion doesn't implement the right rule set for month value.

@jansenbe jansenbe reopened this Apr 4, 2022
@jansenbe
Copy link
Contributor

jansenbe commented Apr 4, 2022

@FlorianLabranche : nice research done @FlorianLabranche , that explains things! I'll update the implementation accordingly.

jansenbe added a commit that referenced this issue Apr 5, 2022
@jansenbe
Copy link
Contributor

jansenbe commented Apr 5, 2022

@FlorianLabranche , @Sean-LM, @TheRealDrNick: I've aligned the CSOM datetime parsing code to what is used inside CSOM itself + added updated test cases. Datetime parsing should now support all cases and be slightly faster as well. The fix will be part of the next nightly build, version 1.6.8 or higher. Closing this issue now, feel free to re-open or create a new one when the issue is still not fixed in your setup.

@jansenbe jansenbe closed this as completed Apr 5, 2022
@FlorianLabranche
Copy link
Author

Thank you @jansenbe !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants