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

Invoke-PnPSiteTemplate : Object reference not set to an instance of an object. #164

Closed
mbalcarek opened this issue Feb 9, 2021 · 8 comments
Assignees
Labels
area: provisioning ⚙ Provisioning engine issue or pull request question Further information is requested Stale Issue has been active for a long time. Stale issues will be closed automatically after 15 days

Comments

@mbalcarek
Copy link

I am trying to copy a customized home page home.aspx from one site collection to another. Both are modern team sites without Teams. Please note there is a home.aspx in both the source and target urls.

`
$pageName = "Home.aspx"

Connect-PnPOnline -Url $srcUrl  -Credentials $UserCredential 

$tempFile = "c:\temp\template.xml"   # [System.IO.Path]::GetTempFileName();

Export-PnPPage -Force -Identity $pageName -Out $tempFile

Connect-PnPOnline -Url $destUrl  -Credentials $UserCredential 

Invoke-PnPSiteTemplate -Path $tempFile

Get-PnPException`

results:

Message : Object reference not set to an instance of an object.
Stacktrace : at PnP.Framework.Provisioning.ObjectHandlers.ObjectClientSidePages.CreatePage(Web web, ProvisioningTemplate template, TokenParser parser, PnPMonitoredScope scope,
BaseClientSidePage clientSidePage, String pagesLibrary, List pagesLibraryList, Int32& currentPageIndex, List`1 preCreatedPages)
at PnP.Framework.Provisioning.ObjectHandlers.ObjectClientSidePages.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser,
ProvisioningTemplateApplyingInformation applyingInformation)
at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation
provisioningInfo, Boolean calledFromHierarchy, TokenParser tokenParser)
at PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.ExecuteCmdlet()
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
ScriptLineNumber : 19

@jansenbe jansenbe self-assigned this Feb 11, 2021
@jansenbe jansenbe added area: provisioning ⚙ Provisioning engine issue or pull request question Further information is requested labels Feb 11, 2021
@jansenbe
Copy link
Contributor

@mbalcarek : can you share the created template (the template.xml file)?

@piteerus
Copy link

Got the same...

Please have mine....

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2020/02/ProvisioningSchema">
  <pnp:Preferences Generator="PnP.Framework, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" />
  <pnp:Templates ID="CONTAINER-TEMPLATE-8DC33C5F9BBB442B8BD82870854E0F56">
    <pnp:ProvisioningTemplate ID="TEMPLATE-8DC33C5F9BBB442B8BD82870854E0F56" Version="1" BaseSiteTemplate="SITEPAGEPUBLISHING#0" Scope="RootSite">
      <pnp:ClientSidePages>
        <pnp:ClientSidePage PromoteAsNewsArticle="false" PromoteAsTemplate="true" Overwrite="true" Title="MixedPage-Template" ThumbnailUrl="" PageName="Templates/MixedPage-Template.aspx">
          <pnp:Header Type="Default" LayoutType="FullWidthImage" TextAlignment="Center" ShowTopicHeader="false" ShowPublishDate="false" TopicHeader="" AlternativeText="" Authors="[]" AuthorByLine="[]" AuthorByLineId="-1" />
          <pnp:Sections>
            <pnp:Section Order="1" Type="OneColumn" BackgroundEmphasis="Neutral">
              <pnp:Controls>
                <pnp:CanvasControl WebPartType="QuickLinks" JsonControlData="{&quot;id&quot;: &quot;c70391ea-0b10-4ee9-b2b4-006d3fcad0cd&quot;, &quot;instanceId&quot;: &quot;e042ed33-d580-4993-9e23-33c06ca84912&quot;, &quot;title&quot;: &quot;Quick links&quot;, &quot;description&quot;: &quot;Quick links&quot;, &quot;dataVersion&quot;: &quot;2.2&quot;, &quot;properties&quot;: {&quot;items&quot;:[],&quot;isMigrated&quot;:true,&quot;layoutId&quot;:&quot;Grid&quot;,&quot;shouldShowThumbnail&quot;:true,&quot;imageWidth&quot;:400,&quot;buttonLayoutOptions&quot;:{&quot;showDescription&quot;:false,&quot;buttonTreatment&quot;:2,&quot;iconPositionType&quot;:2,&quot;textAlignmentVertical&quot;:2,&quot;textAlignmentHorizontal&quot;:2,&quot;linesOfText&quot;:2},&quot;listLayoutOptions&quot;:{&quot;showDescription&quot;:false,&quot;showIcon&quot;:true},&quot;waffleLayoutOptions&quot;:{&quot;iconSize&quot;:1,&quot;onlyShowThumbnail&quot;:false},&quot;hideWebPartWhenEmpty&quot;:true,&quot;dataProviderId&quot;:&quot;QuickLinks&quot;,&quot;webId&quot;:&quot;{siteid}&quot;,&quot;siteId&quot;:&quot;{sitecollectionid}&quot;}, &quot;serverProcessedContent&quot;: {&quot;htmlStrings&quot;:{},&quot;searchablePlainTexts&quot;:{},&quot;imageSources&quot;:{},&quot;links&quot;:{&quot;baseUrl&quot;:&quot;https://{fqdn}{site}&quot;},&quot;componentDependencies&quot;:{&quot;layoutComponentId&quot;:&quot;706e33c8-af37-4e7b-9d22-6e5694d92a6f&quot;}}, &quot;dynamicDataPaths&quot;: {}, &quot;dynamicDataValues&quot;: {}}" ControlId="c70391ea-0b10-4ee9-b2b4-006d3fcad0cd" Order="1" Column="1" />
              </pnp:Controls>
            </pnp:Section>
            <pnp:Section Order="2" Type="TwoColumn">
              <pnp:Controls>
                <pnp:CanvasControl WebPartType="Text" ControlId="9db2789a-661c-40e6-a6f7-9508a509735c" Order="1" Column="1">
                  <pnp:CanvasControlProperties>
                    <pnp:CanvasControlProperty Key="Text" Value="{{Topic:Title}}" />
                  </pnp:CanvasControlProperties>
                </pnp:CanvasControl>
                <pnp:CanvasControl WebPartType="Text" ControlId="9db2789a-661c-40e6-a6f7-9508a509735c" Order="2" Column="1">
                  <pnp:CanvasControlProperties>
                    <pnp:CanvasControlProperty Key="Text" Value="{{Topic:Description}}" />
                  </pnp:CanvasControlProperties>
                </pnp:CanvasControl>
                <pnp:CanvasControl WebPartType="List" JsonControlData="{&quot;id&quot;: &quot;f92bf067-bc19-489e-a556-7fe95f508720&quot;, &quot;instanceId&quot;: &quot;098419d4-440a-4047-abf1-cc7331ad1756&quot;, &quot;title&quot;: &quot;List&quot;, &quot;description&quot;: &quot;List&quot;, &quot;dataVersion&quot;: &quot;1.0&quot;, &quot;properties&quot;: {&quot;isDocumentLibrary&quot;:true,&quot;selectedListId&quot;:&quot;{listid:Documents}&quot;,&quot;selectedListUrl&quot;:&quot;{site}/Shared Documents&quot;,&quot;webRelativeListUrl&quot;:&quot;/Shared Documents&quot;,&quot;webpartHeightKey&quot;:4,&quot;selectedViewId&quot;:&quot;{viewid:Documents,All Documents}&quot;}, &quot;serverProcessedContent&quot;: {&quot;htmlStrings&quot;:{},&quot;searchablePlainTexts&quot;:{&quot;listTitle&quot;:&quot;Documents&quot;},&quot;imageSources&quot;:{},&quot;links&quot;:{}}, &quot;dynamicDataPaths&quot;: {}, &quot;dynamicDataValues&quot;: {&quot;filterBy&quot;:{}}}" ControlId="f92bf067-bc19-489e-a556-7fe95f508720" Order="3" Column="1" />
                <pnp:CanvasControl WebPartType="Custom" JsonControlData="{&quot;id&quot;: &quot;9fb420d0-8958-421d-a64f-bc86fac4b1a5&quot;, &quot;instanceId&quot;: &quot;33c1744c-9112-40dd-a39d-2ca6580dfc65&quot;, &quot;title&quot;: &quot;Topic Videos Browser&quot;, &quot;description&quot;: &quot;Topic Videos Browser&quot;, &quot;dataVersion&quot;: &quot;1.0&quot;, &quot;properties&quot;: {&quot;topicId&quot;:484,&quot;itemsNumber&quot;:10}, &quot;serverProcessedContent&quot;: {&quot;htmlStrings&quot;:{},&quot;searchablePlainTexts&quot;:{},&quot;imageSources&quot;:{},&quot;links&quot;:{}}, &quot;dynamicDataPaths&quot;: {}, &quot;dynamicDataValues&quot;: {}}" ControlId="9fb420d0-8958-421d-a64f-bc86fac4b1a5" Order="1" Column="2" />
                <pnp:CanvasControl WebPartType="People" JsonControlData="{&quot;id&quot;: &quot;7f718435-ee4d-431c-bdbf-9c4ff326f46e&quot;, &quot;instanceId&quot;: &quot;189d9d10-4539-4f96-a1bd-8f6ac3397d54&quot;, &quot;title&quot;: &quot;People&quot;, &quot;description&quot;: &quot;People&quot;, &quot;dataVersion&quot;: &quot;1.3&quot;, &quot;properties&quot;: {&quot;layout&quot;:1,&quot;persons&quot;:[]}, &quot;serverProcessedContent&quot;: {&quot;htmlStrings&quot;:{},&quot;searchablePlainTexts&quot;:{&quot;title&quot;:&quot;Topic Owner&quot;},&quot;imageSources&quot;:{},&quot;links&quot;:{}}, &quot;dynamicDataPaths&quot;: {}, &quot;dynamicDataValues&quot;: {}}" ControlId="7f718435-ee4d-431c-bdbf-9c4ff326f46e" Order="2" Column="2" />
              </pnp:Controls>
            </pnp:Section>
          </pnp:Sections>
        </pnp:ClientSidePage>
      </pnp:ClientSidePages>
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

Please also find the exception

provisioning [dev ≡]> Get-PnPException


Message          : Object reference not set to an instance of an object.
Stacktrace       :    at PnP.Framework.Provisioning.ObjectHandlers.ObjectClientSidePages.CreatePage(Web web, Provisioni
                   ngTemplate template, TokenParser parser, PnPMonitoredScope scope, BaseClientSidePage clientSidePage,
                    String pagesLibrary, List pagesLibraryList, Int32& currentPageIndex, List`1 preCreatedPages)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectClientSidePages.ProvisionObjects(Web web, Prov
                   isioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInfor
                   mation)
                      at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web
                   , ProvisioningTemplate template, ProvisioningTemplateApplyingInformation provisioningInfo, Boolean c
                   alledFromHierarchy, TokenParser tokenParser)
                      at PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.ExecuteCmdlet()
                      at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
ScriptLineNumber : 35

@DmitryVorobyov
Copy link

Same error when trying to deploy some lists/fields to a site. Template XML attached.

ApprovalLists.zip

Error thrown by script line 87:

Invoke-PnPSiteTemplate -Path $templateFileName -Handlers Lists

Get-PnPException output:

Message : Object reference not set to an instance of an object.
Stacktrace : at PnP.Framework.AuthenticationManager.d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at PnP.Framework.AuthenticationManager.<GetAccessTokenAsync>d__45.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at PnP.Framework.AuthenticationManager.d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PnP.PowerShell.Commands.Provisioning.TokenRetrieval.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.<>c.<b__16_3>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at PnP.Framework.Provisioning.ObjectHandlers.PnPProvisioningContext.AcquireToken(String resource, String scope)
at Microsoft.SharePoint.Client.ClientContextExtensions.GetAccessToken(ClientRuntimeContext clientContext)
at Microsoft.SharePoint.Client.ClientContextExtensions.IsAppOnly(ClientRuntimeContext clientContext)
at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.UpdateList(Web web, List existingList, ListInstance templateList, TokenParser parser, PnPMonitoredScope
scope, Boolean isNoScriptSite)
at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser,
ProvisioningTemplateApplyingInformation applyingInformation)
at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template,
ProvisioningTemplateApplyingInformation provisioningInfo, Boolean calledFromHierarchy, TokenParser tokenParser)
at Microsoft.SharePoint.Client.WebExtensions.ApplyProvisioningTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation
applyingInformation)
at PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.ExecuteCmdlet()
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
ScriptLineNumber : 87

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale Issue has been active for a long time. Stale issues will be closed automatically after 15 days label Apr 16, 2021
@KaushalKhamar
Copy link

I am getting this issue while provisioning template. Below is error.

Message          : Object reference not set to an instance of an object.
Stacktrace       :    at Microsoft.SharePoint.Client.FieldAndContentTypeExtensions.BestMatch(String contentTypeId, IEnumerable`1 contentTypeCollection)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.CreateView(Web web, View view, ViewCollection existingViews, List createdList, 
                   PnPMonitoredScope monitoredScope, TokenParser parser, Int32 currentViewIndex, Int32 total)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.ProcessViews(Web web, TokenParser parser, PnPMonitoredScope scope, ListInfo 
                   listInfo)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectListInstance.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, 
                   ProvisioningTemplateApplyingInformation applyingInformation)
                      at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, 
                   ProvisioningTemplateApplyingInformation provisioningInfo, Boolean calledFromHierarchy, TokenParser tokenParser)
                      at PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.ExecuteCmdlet()
                      at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
ScriptLineNumber : 15

@clausewit
Copy link

clausewit commented Jul 28, 2022

I have got the same problem... I got the template with this code from a dev tenant and I can't Import it into the production tenant.

$FilePath = "C:\temp\sitetemplate.xml"

Get-PnPSiteTemplate -Out $FilePath -Handlers PageContents -IncludeAllClientSidePages -PersistBrandingFiles -Force

After connecting to the site, I fire this command, but the error displayed below pops up.

Invoke-PnPSiteTemplate -Path $FilePath

Message : Object reference not set to an instance of an object. Stacktrace : at Microsoft.SharePoint.Client.FieldAndContentTypeExtensions.IsChildOf(ContentTypeId current, ContentTypeId contentTypeId) at PnP.Framework.Provisioning.ObjectHandlers.ObjectClientSidePages.CreatePage(Web web, ProvisioningTemplate template, TokenParser parser, PnPMonitoredScope scope, BaseClientSidePage clientSidePage, String pagesLibrary, List pagesLibraryList, Int32& currentPageIndex, List`1 preCreatedPages) at PnP.Framework.Provisioning.ObjectHandlers.ObjectClientSidePages.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation provisioningInfo, Boolean calledFromHierarchy, TokenParser tokenParser) at Microsoft.SharePoint.Client.WebExtensions.ApplyProvisioningTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation) at PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.ExecuteCmdlet() in D:\a\powershell\powershell\src\Commands\Provisioning\Site\InvokeSiteTemplate.cs:line 327 at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPSharePointCmdlet.cs:line 114 ScriptLineNumber : 39

@CallumCrowley
Copy link

I am getting similar issues with Invoke-PnPSiteTemplate, why was this issue closed?

@ImenTurki
Copy link

am getting the same error , any idea please or other suggestion to copy a site from tenant to another

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: provisioning ⚙ Provisioning engine issue or pull request question Further information is requested Stale Issue has been active for a long time. Stale issues will be closed automatically after 15 days
Projects
None yet
Development

No branches or pull requests

8 participants