Closed erwinvanhunen closed 3 years ago
@bhishma: how do you connect, e.g. which way of connecting with Connect-PnPOnline do you use?
@bhishma: please also share the output from Get-PnPException
which you can call immediately after the error happens.
@erwinvanhunen, I'm using StoredCredentials to connect Connect-PnPOnline -Url "" -Credential "myaccount"
@jansenbe , When I execute Get-PnPException, it does not return anything.
PS C:\Users\testUser> $list=Get-PnPList "SharePoint Sites"
PS C:\Users\testUser> $batch = New-PnPBatch
PS C:\Users\testUser> Add-PnPListItem -List $list -Values @{"Title" ="site1"} -Batch $batch
PS C:\Users\testUser> Add-PnPListItem -List $list -Values @{"Title" ="site2"} -Batch $batch
PS C:\Users\testUser> Invoke-PnPBatch -Batch $batch -Details
ErrorMessage
------------
Invalid file name....
Invalid file name....
Invalid file name....
Invalid file name....
PS C:\Users\testUser> Get-PnPException
PS C:\Users\testUser> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.2.7 PnP.PowerShell {Add-PnPAlert, Add-PnPApp, Add-PnPApplication...
PS C:\Users\testUser> $list
Title Id Url
----- -- ---
SharePoint Sites gudiddd-dac2-460c-b67b-90ffbe9bd11b /sites/test/Lists/SharePoint Sites
Trying to eliminate causes, are the items actually being created? Or you just receive the file not found message? Have you tried without the -Details parameter?
They are not created. I tried without -Details as well. Same result.
The detail lines you see contain more information:
$details = Invoke-PnPBatch -Details
$details | select ResponseJson
We're interested in seeing the full detail of the ResponseJson.
Another thing: could you try to run the Invoke-PnPBatch
cmdlet with the -StopOnException
parameter? It could potentially show more information.
If neither of these steps above return any data:
Are you familiar with Fiddler? If so, we would like to see a fiddler trace. (https://getfiddler.com). Start fiddler, then launch PowerShell (it's important to do it in that order) . Then execute your code. You'll see requests being executed which end on /_api/$batch
. We would also be interested in seeing those requests, that is, the response data returned from those requests.
I can see this in Details but Nothing in ResponseJson.
ErrorMessage ResponseCode Request
------------ ------------ -------
File Not Found. 404 https://domain.sharepoint.com/_api/Web/Lists(guid'guid-9140-40f7-a84f-2e77da87e0d5')/AddValidateUpdateItemUsingPath
File Not Found. 404 https://domain.sharepoint.com/_api/Web/Lists(guid'guid-9140-40f7-a84f-2e77da87e0d5')/AddValidateUpdateItemUsingPath
File Not Found. 404 https://domain.sharepoint.com/_api/Web/Lists(guid'guid-9140-40f7-a84f-2e77da87e0d5')/AddValidateUpdateItemUsingPath
File Not Found. 404 https://domain.sharepoint.com/_api/Web/Lists(guid'guid-9140-40f7-a84f-2e77da87e0d5')/AddValidateUpdateItemUsingPath
If I use StopOnExecution this is the error:
PS C:\Users\testUser> Invoke-PnPBatch $batch -Details -StopOnException
Invoke-PnPBatch : File Not Found.
At line:1 char:1
+ Invoke-PnPBatch $batch -Details -StopOnException
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-PnPBatch], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Base.InvokeBatch
PS C:\Users\testUser> Get-PnPException
Message : File Not Found.
Stacktrace : at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
ScriptLineNumber : 1
I'm behind corporate proxy, I'm not able to connect to SPO if I let Fiddler change proxy. If I use corporate proxy, Fiddler is not capturing the traffic. I'll try to do this on a computer that's not on proxy.
okay, the results you see are actualy error reports from the server. And when looking at the URL for each request I see something strange there. The guid of the list is written as guid'-guid-9140-40f7-etc.
. That's not how it should be written, it should be guid'9140-40f7-etc
. I'm very confused why that is...
I'm moving this issue to the Core SDK and we continue in that repo with this issue.
Sorry for confusion. I meant to not show the real guid here that's why tried to obfuscate. The real error shows GUID properly.
Okay, that explains :-)
In our ongoing investigation, could you run the exact following snippet in a test site?
New-PnPList -Title "PnPTestList" -Template GenericList
$list = Get-PnPList -Identity "PnPTestList"
$batch = New-PnPBatch
1..5 | %{ Add-PnPListItem -List $list -Values @{"Title"="Title $_"} -Batch $batch }
Invoke-PnPBatch $batch -StopOnException
And see what happens? Just to determine if there is something with the list that makes it throw the exception.
I still get same issue:
PS C:\Users\testUser> New-PnPList -Title "PnPTestList" -Template GenericList
Title Id Url
----- -- ---
PnPTestList
PS C:\Users\testUser> $list = Get-PnPList -Identity "PnPTestList"
PS C:\Users\testUser> $batch = New-PnPBatch
PS C:\Users\testUser> 1..5 | %{ Add-PnPListItem -List $list -Values @{"Title"="Title $_"} -Batch $batch }
PS C:\Users\testUser> Invoke-PnPBatch $batch -StopOnException
Invoke-PnPBatch : File Not Found.
At line:1 char:1
+ Invoke-PnPBatch $batch -StopOnException
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-PnPBatch], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Base.InvokeBatch
PS C:\Users\testUser> Get-PnPException
Message : File Not Found.
Stacktrace : at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
ScriptLineNumber : 1
I'm almost starting to wonder if the corporate proxy you mentioned is doing something in between. The main difference between using batching and non-batching is how we make the API calls behind the scenes. When adding an item without batching we use CSOM, when adding a item through batching we use the SharePoint REST api.
Can you try to open this in your browser (where you obviously replace the url with actual tenant name and the id of the list)? You should receive an XML response.
https://domain.sharepoint.com/_api/Web/Lists(guid'9140-40f7-a84f-2e77da87e0d5')
Notice that the id component should be formatted as guid'9a01c1fd-0c00-4acb-bcd4-9947e2047de5'
@bhishma : do you have an update to share?
I think Erwin is correct. Must be the proxy thing. I was able to execute same command outside of proxy. However I do get the XML response when I try to hit the endpoint with proxy too.
We would propose to exclude the SharePoint tenant from the proxy, but it unfortunately stops here for us as we cannot control your proxy.
I'm having the same problem, but I'm not sitting behind a proxy. I tried it with two different tenants, but it's failing for both. Can someone please look at this agian?!
I'm having the same problem, but I'm not sitting behind a proxy. I tried it with two different tenants, but it's failing for both. Can someone please look at this again?!
I am having the same issue, and I a not behind a proxy either.
@ollimenzel and @rtonerii : Are you both using the PnP.PowerShell? What version?
I can confirm that this works fine in PnP.Core via C#.
Hi in the meantime I opened a new report, and it was also reproduceable as you can see here: https://github.com/pnp/powershell/issues/668 It seems to be a problem with the root SiteCollection in my case
@ollimenzel : That root Site Collection was definitely the piece I was missing. I don't know if that's the same issue for @rtonerii or not. I've submitted a PR and will see if it's accepted by @jansenbe .
Thanks for helping out!
@DaleyKD : thanks for helping out and creating the PR @ollimenzel / @rtonerii : I've merged the PR from @DaleyKD , this will be included in the tomorrow's nightly build from PnP PS, so would recommend giving that a try and let us know.
@DaleyKD : thanks for helping out and creating the PR @ollimenzel / @rtonerii : I've merged the PR from @DaleyKD , this will be included in the tomorrow's nightly build from PnP PS, so would recommend giving that a try and let us know.
I have been testing this on a sub-site collection. I installed the latest from today and I am having other issues. Here is the error:
Add-PnPListItem : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan
1
@rtonerii : Could you show me your full Add-PnPListItem
command you're using? (You can omit the tenant if you'd like.)
@DaleyKD Here is the script.
New-PnPList -Title "PnPTestList" -Template GenericList -ErrorAction SilentlyContinue $list = Get-PnPList -Identity "PnPTestList" $batch = New-PnPBatch 1..5 | %{ Add-PnPListItem -List $list -Values @{"Title"="Title $_"} -Batch $batch } Invoke-PnPBatch $batch -Details -Debug
I did some more testing and it works in a PowerShell console window but it errors in the VS Code development environment.
Can you check the PS version where it works (and not works). You get the PS version via $PSVersionTable
Can you check the PS version where it works (and not works). You get the PS version via
$PSVersionTable
Name Value
PSVersion | 5.1.19041.906 PSEdition | Desktop PSCompatibleVersions | {1.0, 2.0, 3.0, 4.0...} BuildVersion | 10.0.19041.906 CLRVersion | 4.0.30319.42000 WSManStackVersion | 3.0 PSRemotingProtocolVersion | 2.3 SerializationVersion | 1.1.0.1
so is the working version (PS console) or the non working version (VS Code)? I want to understand if there's a difference between those. PS version 5 uses .NET Framework while PS version 7+ uses .NET Core / .NET 5
I can try both on monday.
OK, The use happens on both versions.
Only on the root site.
OK, some more updates. I updated my environments to version 1.6.0.
I am now able to successfully process the above script on both the root site and a sub-site collection with PS 7.1.
I am getting the following error on PS 5.1, in VS Code.
Add-PnPListItem : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan
1
Everything works with the regular PowerShell console windows.
It seems as in the 5.1 console version of VS Code some other module is loaded first loading an older version of an assembly (possibly System.Text.Encodings.Web.dll)...when the PS module is loaded afterwards things fail. You could consider switching to PS7 in VS Code (https://rnelson0.com/2020/03/05/using-powershell-7-in-vs-code/).
In general there's no easy fix for this as in PS world modules can easily load conflicting assemblies...best is to not load too many modules by default and then load the modules you need on demand.
It seems as in the 5.1 console version of VS Code some other module is loaded first loading an older version of an assembly (possibly System.Text.Encodings.Web.dll)...when the PS module is loaded afterwards things fail. You could consider switching to PS7 in VS Code (https://rnelson0.com/2020/03/05/using-powershell-7-in-vs-code/).
In general there's no easy fix for this as in PS world modules can easily load conflicting assemblies...best is to not load too many modules by default and then load the modules you need on demand.
Thanks, I will try and make this work.
Pnp Powershell is really not working well with Ps 5.1. Switch to Ps7.
With VsCode :
I'm trying to add list items in a simple site.. but keep getting Invalid file name error:
results in
Invalid file name. The file name you specified could not be used. It may be the name of an existing file or directory, or you may not have permission to access the file.
I'm using Manifest 1.2.0 PnP.PowerShell
Tested with nightly build as well: Manifest 1.2.7 PnP.PowerShell
Note: it works if I remove the batching.
Originally posted by @bhishma in https://github.com/pnp/powershell/discussions/195