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

GetAvailableThemesAsync throws exception when 'isInverted' or 'name' values missing from JSON response #990

Closed
1 task done
kgr-kpmg opened this issue Oct 10, 2022 · 2 comments
Assignees
Labels
area: model 📐 Related to the core SDK models bug Something isn't working

Comments

@kgr-kpmg
Copy link

Category

  • Bug

Describe the bug

Not entirely sure if this is an issue with the theme that was uploaded or with SharePoint or with the SDKs handling of the theme, but presumably SharePoint is treating it as valid.

context.Web.GetBrandingManager().GetAvailableThemesAsync() throws KeyNotFoundException when theme JSON is missing name or isInverted properties.

Steps to reproduce

  1. Upload theme without isInverted or name properties
  2. Try to fetch themes from site using await context.Web.GetBrandingManager().GetAvailableThemesAsync();

Expected behavior

Error is handled and default values provided.

Environment details (development & target environment)

  • SDK version: 1.7.0
  • OS: Windows 10
  • SDK used in: Azure function
  • Framework: .NET 6
  • Browser(s): n/a
  • Tooling: n/a
  • Additional details: See below

Additional context

PnP.Core.Model.SharePoint.BrandingManager.NormalizeThemeJson(String themeJson)

var body = new
{
    backgroundImageUri = "",
    palette = paletteValues,
    cacheToken = "",
    isDefault = true,
    isInverted = customThemeJson.GetProperty("isInverted").GetBoolean(),
    version = ""
};

var final = new
{
    name = customThemeJson.GetProperty("name").GetString(),
    themeJson = JsonSerializer.Serialize(body),
};

Other code in this same method uses TryGetProperty as opposed to GetProperty which causes an exception.

Thanks for your contribution! Sharing is caring.

@jansenbe jansenbe self-assigned this Oct 11, 2022
@jansenbe jansenbe added area: model 📐 Related to the core SDK models bug Something isn't working labels Oct 11, 2022
@jansenbe
Copy link
Contributor

@kgr-kpmg : makes indeed sense to add additional validation on those two properties.

jansenbe added a commit that referenced this issue Oct 11, 2022
@jansenbe
Copy link
Contributor

@kgr-kpmg : a change has been pushed, please test using next nightly release (version 1.7.97 or higher). I'm already closing the issue, but feel free to re-open in case the problem is still not solved for you.

Thanks for using PnP Core SDK and providing feedback!

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