PnP-Sites-Core icon indicating copy to clipboard operation
PnP-Sites-Core copied to clipboard

Get-PnPProvisioningTemplate : Exception has been thrown by the target of an invocation.

Open Pieter-Veenstra opened this issue 6 years ago • 8 comments

Category

[X] Bug [ ] Enhancement

Environment

[ ] Office 365 / SharePoint Online [X] SharePoint 2016 [ ] SharePoint 2013

If SharePoint on-premises, what's exact CU version: 16.0.4651.1000

Observed Behavior

I first tried applying a template and I got the similar Exception has been thrown by the target of an invocation. Then I tried to get the template and got the error again.

Steps to Reproduce

I'm not sure how to reproduce this as it doesn't happen in my development environment but it does happen in the customer environment.

The problem only occurs in the Fields handler. Looking at the first errors it looks like PnP is struggling to get the base template of the site. However when I run the Contenttype handler only a template is extracted successfully.

PS D:\install\Deployment> Get-PnPProvisioningTemplate -Handlers Fields
PowerShell_ISE.exe Error: 0 : 2018-03-02 11:44:23.5896	[Provisioning]	[0]	[Error]	Error occured while retrieving basetemplate	0ms	
PowerShell_ISE.exe Error: 0 : 2018-03-02 11:44:23.6208	[Provisioning]	[0]	[Error]	Error occured while retrieving basetemplate	0ms	
PowerShell_ISE.exe Information: 0 : 2018-03-02 11:44:23.6208	[Extraction]	[12]	[Debug]	Code execution scope started	0ms	4d299638-ea96-4156-abe5-bc9f
bf6d4d7b
PowerShell_ISE.exe Information: 0 : 2018-03-02 11:44:23.6208	[Extraction]	[12]	[Debug]	ProgressDelegate registered	1ms	4d299638-ea96-4156-abe5-bc9fb
f6d4d7b
PowerShell_ISE.exe Information: 0 : 2018-03-02 11:44:23.6208	[Extraction]	[12]	[Debug]	MessagesDelegate registered	1ms	4d299638-ea96-4156-abe5-bc9fb
f6d4d7b
PowerShell_ISE.exe Information: 0 : 2018-03-02 11:44:23.6364	[Fields]	[12]	[Debug]	Code execution scope started	0ms	4d299638-ea96-4156-abe5-bc9fbf6d
4d7b
PowerShell_ISE.exe Information: 0 : 2018-03-02 11:44:23.8708	[Fields]	[12]	[Debug]	Code execution scope ended	244ms	4d299638-ea96-4156-abe5-bc9fbf6d
4d7b
PowerShell_ISE.exe Information: 0 : 2018-03-02 11:44:23.8708	[Extraction]	[12]	[Debug]	Code execution scope ended	249ms	4d299638-ea96-4156-abe5-bc9f
bf6d4d7b
Get-PnPProvisioningTemplate : Exception has been thrown by the target of an invocation.
At line:1 char:1
+ Get-PnPProvisioningTemplate -Handlers Fields
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPProvisioningTemplate], ServerException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.GetProvisioningTemplate

Then I tried excluding the Fields handler only and the Lists gave me the same exception. Then I excluded the Lists and Fields and the template was extracted successfully.

Taking this a bit further, I then ran the following PowerShell:

$web = Get-PnPWeb
$web.Context.Load($web.Fields)
$web.Context.ExecuteQuery()

and this returns:

Exception calling "ExecuteQuery" with "0" argument(s): "Exception has been thrown by the target of an invocation."
At line:1 char:1
+ $web.Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ServerException

It looks like it is impossible to get CSOM to load my Fields.

I just checked in the SharePoint interface and the site columns management area gives me a similar issue. It looks like something got corrupted somewhere.

After more investigation I found the issue.

When applying a template from one farm to another farm the termset used by a managed metadata column may not exist, When this occurs the managed metadata column is created nbut corrupt:

This then results in a sitaation as de described here:

http://blog.sharepointsite.co.uk/2011/05/corrupt-site-column-cannot-be-deleted.html

Pieter-Veenstra avatar Mar 02 '18 11:03 Pieter-Veenstra

@VesaJuvonen, this is quite a major issue. The termsets inside my template should have been created by the template however the columns got created first. Then my site column became unusable until I went through the unsupported option found in the link above. Applying a PnP template should corrupt SharePoint databases.

Pieter-Veenstra avatar Mar 02 '18 14:03 Pieter-Veenstra

Step #1 for us would be to be able to reproduce the issue so that we can investigate that what goes wrong. It's important to realize that PnP does NOT do any tricks, it just uses oob CSOM / REST APIs for the operations, so this is now implying that there's something wrong in oob API surface depending on the sequence of calls.

Based on your description, you have NOT created the site or the objects on the site using a template or the sequence was not clear. You could always pull down the source code and do debugging to understand where and why this is failing.

If the situation is that you can't reproduce the issue in any other tenants - there's really no way for us fixing this either, since that indicates that it's site collection specific thing. Potentially something else in the past has performed some operations which have then caused the issue. This is on-premises deployment, so there could have been different server-side operations causing this.

Unfortunately just by looking on the description and exception details we can see that the template extraction is failing like the oob API call is failing... root cause based on provided details is not clear with this setup.

If the issue was a result of applying a template, we would need to understand what the template contains and how it was applied to the site.

VesaJuvonen avatar Mar 02 '18 15:03 VesaJuvonen

Hi Vesa, I agree, this is likely something caused by a problem in the CSOM API. I will spend some time in Monday debugging this, when I have access to my development systems. Thanks, Pieter

Pieter-Veenstra avatar Mar 02 '18 16:03 Pieter-Veenstra

Hi Vesa, I have now found a way yo reproduce the issue. Have two SharePoint farms (on premises 2016 in my case). Then create a term group and create a managed metadata column. The export the site with get PnP provisioning template and apply this yr late to a clean 2016 farm that doesn't have the term group used created yet. Even though my term info is in the template xml the field is created before the terms are created. This results in the database corruption. Yes the API shouldn't allow for this but within PnP we could probably re order the creation of the terms and the creation of the columns.

Pieter-Veenstra avatar Mar 11 '18 16:03 Pieter-Veenstra

@VesaJuvonen i have the same issue - looks like when i create a template in O365 tenantA and apply to site in tenantB .. this issue appears...

suz7777 avatar Dec 22 '18 17:12 suz7777

@VesaJuvonen I am also facing the same issue with the Managed Metadata Column. Any resolution for this?

SathishNadarajan avatar May 29 '19 15:05 SathishNadarajan

We now seem to have three different issues with the same topic

  • https://github.com/SharePoint/PnP-Sites-Core/issues/1366
  • https://github.com/SharePoint/PnP-Sites-Core/issues/1951
  • and this one here.

The issue still persists and can be recreated with a Taxonomy Field using a local Taxonomy Group, being deployed by PnP.

Leviani avatar Dec 17 '19 23:12 Leviani

Actual State is, that it is not possible to apply an PnPProvisioningTemplate from one web to another web (Tenant) due to this Managed Metadata Taxononmy specific Provisioning Bug. Any Updates or planned Fixes?

schneika avatar Sep 01 '20 15:09 schneika