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

Add-PnPPage: Object reference not set to an instance of an object when trying to create a new page #3959

Open
1 task done
borjaevo opened this issue May 15, 2024 · 4 comments

Comments

@borjaevo
Copy link

Category

  • Bug

Describe the bug

Im trying to migrate a classic site into a modern one. I already have the connected 365 group and i can use modern lists and libraries. But i have pages, like the homepage that are classic and when this page is displayed the menu is the classic one too so the user is confused. I dont want to migrate any of those pages, i tried and get other errors so i delete all of them. Now, im trying to create a new modern page using PnP. Im using command Add-PnPPage.

Steps to reproduce

DELETE THIS LINE BEFORE SUBMITTING - Provide steps to reproduce the behavior:

  1. Im using powershell 7 and PnP installed yesterday version 2.4.0
  2. Auth using Connect-PnPOnline -Url "https://----.sharepoint.com/calidad" -Credential (Get-Credential)
  3. Execute command $pagename = "Welcome"
  4. Execute command $page = Add-PnPPage -Name $pagename -LayoutType Home
  5. See error: Add-PnPPage: Object reference not set to an instance of an object.

Expected behavior

The modern page to be created. A file is created instead but is corrupted.

Environment details (development & target environment)

  • SDK version: 2.4.0
  • OS: Windows 11

Additional context

What i want to achieve is my users only have to see one menu, and not be changing between different designs. I can't recreate the entire site because it has a lot of list with powerautomate flows.

@jansenbe jansenbe transferred this issue from pnp/pnpcore May 17, 2024
@jackpoz
Copy link
Contributor

jackpoz commented May 19, 2024

Could you please run these commands and post the output ?

$pagename = "Welcome"
$page = Add-PnPPage -Name $pagename -LayoutType Home -ErrorAction:Stop
(Get-PnPException).Exception | Select-Object *

If I run this on a site without "Site Pages" library and without any library of type "Page library", like a brand new site with "Publishing Portal" template, this is the error I get:
image

If I then create the Page library, this is what I get:
image

This follow-up issue happens because somehow there's no field called _AuthorByline.

@jackpoz
Copy link
Contributor

jackpoz commented May 19, 2024

@jansenbe should Page.EnsurePagesLibraryAsync() method in PnP Core at https://github.com/pnp/pnpcore/blob/40b870c5170b3d824dc278414d889c86c32f8037/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs#L475 create a Page library if none exists ? There's no call to the CSOM method ListCollection.EnsureSitePagesLibrary() to create the library when missing and the method returns null in that case.

@borjaevo
Copy link
Author

Could you please run these commands and post the output ?

$pagename = "Welcome"
$page = Add-PnPPage -Name $pagename -LayoutType Home -ErrorAction:Stop
(Get-PnPException).Exception | Select-Object *

If I run this on a site without "Site Pages" library and without any library of type "Page library", like a brand new site with "Publishing Portal" template, this is the error I get: image

If I then create the Page library, this is what I get: image

This follow-up issue happens because somehow there's no field called _AuthorByline.

Yes, i have exactly same errors

@borjaevo
Copy link
Author

@jansenbe should Page.EnsurePagesLibraryAsync() method in PnP Core at https://github.com/pnp/pnpcore/blob/40b870c5170b3d824dc278414d889c86c32f8037/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs#L475 create a Page library if none exists ? There's no call to the CSOM method ListCollection.EnsureSitePagesLibrary() to create the library when missing and the method returns null in that case.

Can i create the library manually some way? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants