PnP.PowerShell 0.3.30
I have created a modules folder inside the Azure function and uploaded the files for the latest build.
When calling Invoke-PnPSiteTemplate in an Azure Function which has the following ClientSidePages element (see below) I receive an error stating "ERROR: The given key was not present in the dictionary.Exception :Type : System.Collections.Generic.KeyNotFoundExceptionTargetSite"
If I remove the ClientSidePages elements from the template and re-run the Azure Function it completes without any errors.
Running the same code on my machine and calling Invoke-PnPSiteTemplate with the original template, which includes the ClientSitePages element, works successfully without any issues. The only difference in the code between running locally and in the Azure function is on Connect-PnPOnline, locally I use PnPManagementShell and in the Azure function I am using ClientId, Thumbprint and Tenant.
<pnp:ClientSidePages>
<pnp:ClientSidePage PromoteAsNewsArticle="false" PromoteAsTemplate="false" Overwrite="true" Layout="Home" EnableComments="false" Title="Home" ThumbnailUrl="" PageName="Home.aspx">
<pnp:Header Type="Default" LayoutType="FullWidthImage" TextAlignment="Center" ShowTopicHeader="false" ShowPublishDate="false" TopicHeader="" AlternativeText="" Authors="" AuthorByLineId="-1" />
<pnp:Sections>
<pnp:Section Order="1" Type="OneColumn">
<pnp:Controls>
<pnp:CanvasControl WebPartType="Text" ControlId="247bcd25-a96b-4c2d-a93e-5c0d2b792e21" Order="1" Column="1">
<pnp:CanvasControlProperties>
<pnp:CanvasControlProperty Key="Text" Value="<p>Welcome to Azure Created Site</p><p><br></p>" />
</pnp:CanvasControlProperties>
</pnp:CanvasControl>
</pnp:Controls>
</pnp:Section>
</pnp:Sections>
</pnp:ClientSidePage>
</pnp:ClientSidePages>
The error message in the Azure Function is:
ERROR: The given key was not present in the dictionary.Exception :
Type : System.Collections.Generic.KeyNotFoundExceptionTargetSite :
Name : GetPropertyDeclaringType : System.Text.Json.JsonElementMemberType :
MethodModule : System.Text.Json.dllStackTrace :at System.Text.Json.JsonElement.GetProperty(String propertyName)at PnP.Core.SharePointRestError.ParseError(JsonElement error)at
PnP.Core.SharePointRestError..ctor(ErrorType type, Int32 httpResponseCode, String response)at PnP.Core.SharePointRestServiceException..ctor(ErrorType type, Int32 httpResponseCode, String response)at
PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch)at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)at
PnP.Core.Model.BaseDataModel1.RequestAsync(ApiCall apiCall, HttpMethod method)at PnP.Core.Services.PnPContextFactory.InitializeContextAsync(PnPContext context)at
PnP.Core.Services.PnPContextFactory.CreateAsync(Uri url, IAuthenticationProvider authenticationProvider)at
PnP.Core.Services.PnPContextFactory.Create(Uri url, IAuthenticationProvider authenticationProvider)at
PnP.Framework.PnPCoreSdk.GetPnPContext(ClientContext context)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()at
PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPSharePointCmdlet.cs:line 59
Message : The given key was not present in the dictionary.Data : System.Collections.ListDictionaryInternalSource : System.Text.JsonHResult : -2146232969CategoryInfo
: WriteError: (:) [Invoke-PnPSiteTemplate], KeyNotFoundExceptionFullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplateErrorDetails
: The given key was not present in the dictionary.InvocationInfo :MyCommand : Invoke-PnPSiteTemplateScriptLineNumber : 64
OffsetInLine : 5HistoryId : 1ScriptName : D:\home\site\wwwroot\xxxxxxxxxxxxxxx\run.ps1Line
: Invoke-PnpSiteTemplate -Path "D:\home\site\wwwroot\PnPTemplates\xxxxxxxxxxxxxxx.xml" -ClearNavigationPositionMessage : At
D:\home\site\wwwroot\xxxxxxxxxxxxxxx\run.ps1:64 char:5+
Invoke-PnpSiteTemplate -Path "D:\home\site\wwwroot\PnPTemplates\A …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot :
D:\home\site\wwwroot\xxxxxxxxxxxxxxxxxxxxx : D:\home\site\wwwroot\xxxxxxxxxxxxxxxx\run.ps1
InvocationName : Invoke-PnpSiteTemplateCommandOrigin
: InternalScriptStackTrace : at <ScriptBlock>, D:\home\site\wwwroot\xxxxxxxxxxxxxxx\run.ps1: line 64PipelineIterationInfo :Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException :
Result: ERROR: The given key was not present in the dictionary.Exception :Type :
System.Collections.Generic.KeyNotFoundExceptionTargetSite :Name : GetPropertyDeclaringType : System.Text.Json.JsonElementMemberType
: MethodModule : System.Text.Json.dllStackTrace :at System.Text.Json.JsonElement.GetProperty(String propertyName)at
PnP.Core.SharePointRestError.ParseError(JsonElement error)at PnP.Core.SharePointRestError..ctor(ErrorType type, Int32 httpResponseCode, String response)at
PnP.Core.SharePointRestServiceException..ctor(ErrorType type, Int32 httpResponseCode, String response)at
PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch)at
PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)at PnP.Core.Model.BaseDataModel1.RequestAsync(ApiCall apiCall, HttpMethod method)at
PnP.Core.Services.PnPContextFactory.InitializeContextAsync(PnPContext context)at
PnP.Core.Services.PnPContextFactory.CreateAsync(Uri url, IAuthenticationProvider authenticationProvider)at
PnP.Core.Services.PnPContextFactory.Create(Uri url, IAuthenticationProvider authenticationProvider)at
PnP.Framework.PnPCoreSdk.GetPnPContext(ClientContext context)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()at
PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPSharePointCmdlet.cs:line 59
Message : The given key was not present in the dictionary.Data : System.Collections.ListDictionaryInternalSource : System.Text.JsonHResult : -2146232969CategoryInfo
: WriteError: (:) [Invoke-PnPSiteTemplate], KeyNotFoundExceptionFullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplateErrorDetails
: The given key was not present in the dictionary.InvocationInfo :MyCommand : Invoke-PnPSiteTemplateScriptLineNumber : 64OffsetInLine : 5HistoryId
: 1ScriptName : D:\home\site\wwwroot\CreateCIMAccountSiterun.ps1Line
: Invoke-PnpSiteTemplate -Path "D:\home\site\wwwroot\PnPTemplates\xxxxxxxxxxxxxxx.xml" -ClearNavigationPositionMessage
: At D:\home\site\wwwroot\CreateCIMAccountSiterun.ps1:64 char:5+
Invoke-PnpSiteTemplate -Path "D:\home\site\wwwroot\PnPTemplates\A …+
~~~~~~~~~~~~~PSScriptRoot
: D:\home\site\wwwroot\xxxxxxxxxxxxxxxPSCommandPath
: D:\home\site\wwwroot\xxxxxxxxxxxxxxxrun.ps1InvocationName
: Invoke-PnpSiteTemplateCommandOrigin : InternalScriptStackTrace : at
PipelineIterationInfo :Exception: The given key was not present in the dictionary.Stack:
at System.Text.Json.JsonElement.GetProperty(String propertyName)at PnP.Core.SharePointRestError.ParseError(JsonElement error)at
PnP.Core.SharePointRestError..ctor(ErrorType type, Int32 httpResponseCode, String response)at
PnP.Core.SharePointRestServiceException..ctor(ErrorType type, Int32 httpResponseCode, String response)at
PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch)at
PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)at
PnP.Core.Model.BaseDataModel`1.RequestAsync(ApiCall apiCall, HttpMethod method)at
PnP.Core.Services.PnPContextFactory.InitializeContextAsync(PnPContext context)at
PnP.Core.Services.PnPContextFactory.CreateAsync(Uri url, IAuthenticationProvider authenticationProvider)at
PnP.Core.Services.PnPContextFactory.Create(Uri url, IAuthenticationProvider authenticationProvider)at
PnP.Framework.PnPCoreSdk.GetPnPContext(ClientContext context)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()at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPSharePointCmdlet.cs:line 59
Did you grant the needed permissions to the app used by the certificate? It goes wrong on the first API call being made by the underlying PnP Core SDK (the pages API is in PnP Core SDK).
When you try with the certificate from your local machine does it then work?
The app has Sites.FullControl.All . The only part of the template which doesn't work is the ClientSidePages, the other parts like WebSettings, RegionalSettings and Features are applied successfully.
I will try tomorrow with the certificate locally and let you know.
I tried running the code locally using the certificate and received the same error message Invoke-PnPSiteTemplate: The given key was not present in the dictionary.
Again, after removing the pnp:clientsidepages section of the template the command runs without any errors.
I ran Get-PnPException after the failure:
Message : The given key was not present in the dictionary.
Stacktrace : at System.Text.Json.JsonElement.GetProperty(String propertyName)
at PnP.Core.SharePointRestError.ParseError(JsonElement error)
at PnP.Core.SharePointRestError..ctor(ErrorType type, Int32 httpResponseCode, String response)
at PnP.Core.SharePointRestServiceException..ctor(ErrorType type, Int32 httpResponseCode, String response)
at PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch)
at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)
at PnP.Core.Model.BaseDataModel1.RequestAsync(ApiCall apiCall, HttpMethod method)
at PnP.Core.Services.PnPContextFactory.InitializeContextAsync(PnPContext context)
at PnP.Core.Services.PnPContextFactory.CreateAsync(Uri url, IAuthenticationProvider authenticationProvider)
at PnP.Core.Services.PnPContextFactory.Create(Uri url, IAuthenticationProvider authenticationProvider)
at PnP.Framework.PnPCoreSdk.GetPnPContext(ClientContext context)
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 363
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\PnPSharePointCmdlet.cs:line 59
ScriptLineNumber : 1`
I'm getting the same error with Invoke-PnPSiteTemplate, plus I get it with "Get-PnPSiteTemplate" when I'm trying to generate a template file.
@Nibushi / @KellyDJones : would you be able to capture a fiddler trace and send that to me ([email protected]) or alternatively find the failing request and check paste the information returned by the server
@Nibushi / @KellyDJones : what's the auth model you're using when connecting to PnP PowerShell?
Regarding Fiddler I will try and get this done today if I can.
With regards to the auth model being used do you mean which parameter set am I using with Connect-PnPOnline? Just in case I am using Tenant, Thumbprint and ClientId.
Apologies if that is not what you were looking for.
@jansenbe - just ran into this one as well.
This also happens when using certificatePath with password:
$connection = Connect-PnPOnline -Url $url -CertificatePath "" -Tenant "" -CertificatePassword $securePass -ClientId "" -ReturnConnection -ErrorAction Stop
Invoke-PnPSiteTemplate template.xml
The template is a simple PnP template containing a modern page with text webpart.
The AAD app has application permissions - Sites.FullControl.All, TermStore.ReadWrite.All, Directory.Read.All
Trying not to go off topic with the template issue but I just noticed that I must have connected locally using a similar command and parameters as @gautamdsheth rather than using Tenant, Thumbprint and ClientId as I had said.
If I run Connect-PnPOnline locally using the certificate (stored in the local machine certificate store) the following command fails when using PnP.PowerShell (0.3.32):
Connect-PnPOnline -Url $Url -Tenant $tenant -Thumbprint $thumbprint -ClientId $clientId
Error message: Connect-PnPOnline: Keyset does not exist
Message : Keyset does not exist
Stacktrace : at PnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord() in D:\a\powershell\powershell\src\Commands\Base\ConnectOnline.cs:line 293
at System.Management.Automation.CommandProcessor.ProcessRecord()
ScriptLineNumber : 1
If I run the exact same command and parameters (Tenant, Thumbprint and ClientId ) on my local machine but use SharePointPnPPowerShellOnline (3.22.2006.2) the Connect-pnponline command works.
Sorry for the detour but it seemed important to mention. I will look at getting the Fiddler trace.
@jansenbe I have sent the fiddler trace as requested.
We fixed this issue in the upcoming nightly release of PnP PowerShell, version 0.3.33-nightly
I can confirm that I am able to successfully apply my template using the 0.3.33 build of PnP.PowerShell.
I am still getting the Connect-PnPOnline: Keyset does not exist error when using Tenant, Thumbprint and ClientId locally but I will open a separate issue for that.
Thanks for resolving the issue with Invoke-pnpsitetemplate
Most helpful comment
We fixed this issue in the upcoming nightly release of PnP PowerShell, version 0.3.33-nightly