question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invoke-PnPSiteTemplate - Azure Function - Given Key not present dictionary

See original GitHub issue

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="&lt;p&gt;Welcome to Azure Created Site&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;" /> </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\CreateCIMAccountSite\run.ps1Line
: Invoke-PnpSiteTemplate -Path “D:\home\site\wwwroot\PnPTemplates\xxxxxxxxxxxxxxx.xml” -ClearNavigationPositionMessage
: At D:\home\site\wwwroot\CreateCIMAccountSite\run.ps1:64 char:5+
Invoke-PnpSiteTemplate -Path "D:\home\site\wwwroot\PnPTemplates\A …+

: D:\home\site\wwwroot\xxxxxxxxxxxxxxxPSCommandPath    
: D:\home\site\wwwroot\xxxxxxxxxxxxxxx\run.ps1InvocationName   
: Invoke-PnpSiteTemplateCommandOrigin    : InternalScriptStackTrace      : at <ScriptBlock>, D:\home\site\wwwroot\xxxxxxxxxxxxxxx\run.ps1: line 64
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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
erwinvanhunencommented, Jan 11, 2021

We fixed this issue in the upcoming nightly release of PnP PowerShell, version 0.3.33-nightly

1reaction
Nibushicommented, Jan 11, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Queue Triggered Function - The given key '$request' ...
I have a function app running in Azure, most functions are HTTP triggers and ... The given key '$request' was not present in...
Read more >
Automation account runbook error The given key was not ...
Dear when I setup the schedule to run runbooks there was an execution happened. warning: Unable to set default context 'Microsoft.Azure.Commands.Common.
Read more >
Auto-configuring SharePoint Sites with Site Templates
How to automatically configure SharePoint sites by utilizing SharePoint Site Templates and PnP Templates, executed by Azure resources.
Read more >
The given key was not present in the dictionary
When you create a template which contains a look up, and copy it into a different site, the referenced list no longer exists....
Read more >
PnP PowerShell V4 Provisioning with Azure Functions V3 ...
Create a new HTTP Trigger function, by selecting the options as shown below; Scroll down, name the function InvokePnPSiteTemplate; Set ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found