pnp / pnp/pnpframework

Term group xml template validation fails randomly in Powershell 7

Open
#502 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
259
Forks
161
Avg merge
10h 33m
Merged PRs (30d)
1

Description

Hello,

Since we started using Powershell 7 (currently on 7.1.5) and the new PnP Framework (at 1.8.0 but also saw the issue in 1.7.0) we started having issues running the Import-PnPTermGroupFromXml cmdlet to import terms into the termstore. From my pretty extensive testing, I have seen that is works in some powershell sessions but not others; When it fails, it may or may not help closing the window and starting a new session. When a session has failed, I have not been able to do anything to get it working, and vice versa.

We get the message "Template is not valid" and a stacktrace that looks like this:

at PnP.Framework.Provisioning.Providers.Xml.XmlPnPSchemaBaseSerializer`1.ProcessInputStream(Strea
m template, String identifier, ProvisioningTemplate result)
at PnP.Framework.Provisioning.Providers.Xml.XmlPnPSchemaBaseSerializer`1.ToProvisioningTemplate(S
tream template, String identifier)
at PnP.Framework.Provisioning.Providers.Xml.XmlPnPSchemaBaseSerializer`1.ToProvisioningTemplate(S
tream template)
at PnP.PowerShell.Commands.Taxonomy.ImportTermGroupFromXml.ExecuteCmdlet() in c:\build\src\Comman
ds\Taxonomy\ImportTermGroupFromXml.cs:line 65
at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPS
harePointCmdlet.cs:line 60

I started out with a big term store import file, but have scaled it down to a very small one exported by the PnP functionality itself from the same tenant. I also tried changing encoding of the file a bit back and forth, and I tried changing the schema version to older versions, but none of this made any difference. I also tried to load the file into a string and use the -Xml parameter instead of -Path, but that caused the same issue so I don't think it is a problem with the file as such. As mentioned, I get different results with the same file just from session to session.

I followed it down to this line where the validation has gone wrong:

https://github.com/pnp/pnpframework/blob/b831d1efde494d2031369dd79ea4b9ccb0f35d4f/src/lib/PnP.Framework/Provisioning/Providers/Xml/XmlPnPSchemaBaseSerializer.cs#L140

I tried following the code all the way, it's not that easy to follow without debugging or tracing, it looks like it is doing a bit of manipulation of the xml before it ends up here, and the xml and schema are being loaded into different stream objects, if that could be a source of error somehow.

I did uninstall parallell versions of PnP that were installed on my machine (in different scopes) and have tried to verify that it uses the .net 5 libraries that are installed with Powershell 7, from what I can see it should do so. I also tried it on a second machine, a server with quite a different setup, and got the same behaviour.

I have been trying to use the Set-PnPTraceLog cmdlet to get some more info into a tracelog, but haven't really been able to get any, at some point it wrote an empty file but that's it. The diagnostics that I suppose should get logged here, can anyone tell me where that ends up?

https://github.com/pnp/pnpframework/blob/b831d1efde494d2031369dd79ea4b9ccb0f35d4f/src/lib/PnP.Framework/Provisioning/Providers/Xml/XmlPnPSchemaBaseSerializer.cs#L81

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing Import-PnPTermGroupFromXml with the minimal exported XML under PowerShell 7.1.5, then read XmlPnPSchemaBaseSerializer.cs at lines 81 and 140 and ImportTermGroupFromXml.cs at line 65. Done means identifying why identical sessions intermittently reject the template and providing a reliable fix or a documented diagnosis of the trace output.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.