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

GetPagesAsync fails with pageHeader translateX or translateY as nulls #740

Closed
1 task done
jjtoscano opened this issue Feb 1, 2022 · 9 comments
Closed
1 task done
Assignees
Labels
area: pages API 📄 Working with modern pages bug Something isn't working

Comments

@jjtoscano
Copy link

jjtoscano commented Feb 1, 2022

Category

  • Bug

Describe the bug

When you retrieve a modern page whose header image has not been modified and has been left empty by default, a deserialization error occurs that leaves the following trace:

System.InvalidOperationException: The requested operation requires an element of type 'Number', but the target element has type 'Null'.
   at System.Text.Json.JsonDocument.TryGetValue(Int32 index, Decimal& value)
   at System.Text.Json.JsonElement.GetDecimal()
   at PnP.Core.Model.SharePoint.PageHeader.FromHtml(String pageHeaderHtml)
   at PnP.Core.Model.SharePoint.Page.LoadFromHtml(String html, String pageHeaderHtml)
   at PnP.Core.Model.SharePoint.Page.LoadPageAsync(IList pagesLibrary, IListItem item)
   at PnP.Core.Model.SharePoint.Page.LoadPagesAsync(PnPContext context, String pageName)
   at PnP.Core.Model.SharePoint.Web.GetPagesAsync(String pageName)

This deserialization error occurs because the page header internally has the translateX and translateY properties null.

Steps to reproduce

1. Create a modern page without modifying the header.
2. Retrieve the modern page with the function GetPagesAsync

or

  1. Download the repo: https://github.com/jjtoscano/pnp-core-getpagesasync-bug
  2. Debug and launch the console app

Expected behavior

The modern page should now be retrieved correctly when the translateX and translateY properties are null.

Environment details (development & target environment)

  • SDK version: 1.5.0
  • OS: MacOS 12.1
  • SDK used in: Web API
  • Framework: .NET 6.0.100
  • Browser(s): NA
  • Tooling: VS Code
  • Additional details: The failure occurs by consuming the GetPagesAsync function

Additional context

The method FromHtml fails when it tries to get a decimal over a null type:

image

This happens on lines 281 and 303 of the PageHeader class.

Thanks for your contribution! Sharing is caring.

@cpercarb
Copy link

cpercarb commented Feb 1, 2022

I am also facing exactly the same issue in my code. Please let us know about it when you have any findings. Thanks in advance!

@jansenbe jansenbe self-assigned this Feb 1, 2022
@jansenbe jansenbe added area: pages API 📄 Working with modern pages question Further information is requested labels Feb 1, 2022
@jansenbe
Copy link
Contributor

jansenbe commented Feb 1, 2022

Thanks @jjtoscano and @cpercarb : seems like something changed in the backend, I'll have a look and will fix this.

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

jansenbe commented Feb 1, 2022

@jjtoscano / @cpercarb : I'm not able to simulate this. So you manually create a modern page and just save it as is and you get the error?

@jansenbe
Copy link
Contributor

jansenbe commented Feb 1, 2022

@jjtoscano / @cpercarb : would be good if one of you can put a breakpoint on line 199 in PageHeader.cs and share the value of the decoded string variable.

@jjtoscano
Copy link
Author

hi @jansenbe, this is the content of the 'decoded' variable:

{"id":"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788","instanceId":"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788","title":"Title Region","description":"description Region","audiences":[],"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{},"imageSources":{"imageSource":"https://xxxxx.sharepoint.com/sites/Noticiasmash/SiteAssets/xxxxx%20logra%20el%20certificado%20Top%20Employer%202022%20en%20Espan%CC%83a%20Brasil,%20Me%CC%81xico%20Australia%20Canada%CC%81%20y%20EEUU.png"},"links":{},"customMetadata":{"imageSource":{}}},"dataVersion":"1.4","properties":{"title":"xxxxx logra el certificado ‘Top Employer 2022’ en España, Brasil, México, Australia, Canadá y EEUU","imageSourceType":2,"type":0,"authorByline":[],"topicHeader":"","layoutType":"FullWidthImage","textAlignment":"Left","showTopicHeader":false,"showPublishDate":false,"authors":[],"imageServerRelativeUrl":null,"translateX":null,"translateY":null,"altText":null,"enableGradientEffect":true},"reservedHeight":280}

@jjtoscano / @cpercarb : I'm not able to simulate this. So you manually create a modern page and just save it as is and you get the error?

Sorry, I've been reviewing it and these are pages that have been created programmatically with the old OfficeDevPnP.Core.Pages library. If you review the generated JSON, internally these properties (translateX, translateY) are left marked null, which causes the issue when trying to retrieve a decimal from a null value using the GetPagesAsync method.

@jansenbe
Copy link
Contributor

jansenbe commented Feb 1, 2022

Thanks for the details @jjtoscano : the snippet shows the imageSource property is set, which normally is not set when there's no header. So in your case you're having a page with an image header set and translateX and translateY is null. I'll add a check to only process those properties when there's a number, that should fix your case.

jansenbe added a commit that referenced this issue Feb 1, 2022
@jansenbe
Copy link
Contributor

jansenbe commented Feb 1, 2022

@jjtoscano / @cpercarb : a fix has been committed. Please try again with tomorrow's nightly build and let me know if things work (or not). Thanks for bubbling up this issue.

@jjtoscano
Copy link
Author

@jansenbe , I've been testing with the preview version "1.5.47-nightly" and it works fine with null values for the "translateX" and "translateY" properties. There is no trace of exceptions.

Thank you very much for the quick response and fix! 💯

@jansenbe
Copy link
Contributor

jansenbe commented Feb 2, 2022

Awesome! Closing issue now

@jansenbe jansenbe closed this as completed Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: pages API 📄 Working with modern pages bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants