Invoke-PnPSiteTemplate - Azure Function - Given Key not present dictionary
See original GitHub issuePnP.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.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
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:
- Created 3 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
We fixed this issue in the upcoming nightly release of PnP PowerShell, version 0.3.33-nightly
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.