Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm trying to add list items in a simple site.. but keep getting Invalid file name error: #312

Closed
erwinvanhunen opened this issue Jan 29, 2021 · 34 comments · Fixed by #470
Closed
Assignees
Labels
area: model 📐 Related to the core SDK models question Further information is requested

Comments

@erwinvanhunen
Copy link
Member

I'm trying to add list items in a simple site.. but keep getting Invalid file name error:

$batch = New-PnPBatch
Add-PnPListItem -List $list -Values @{"Title" ="site1"} -Batch $batch
Add-PnPListItem -List $list -Values @{"Title" ="site2"} -Batch $batch
Add-PnPListItem -List $list -Values @{"Title" ="site3"} -Batch $batch   
$details= Invoke-PnPBatch -Batch $batch -Details

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 pnp/powershell#195

@erwinvanhunen erwinvanhunen self-assigned this Jan 29, 2021
@erwinvanhunen
Copy link
Member Author

@bhishma: how do you connect, e.g. which way of connecting with Connect-PnPOnline do you use?

@jansenbe
Copy link
Contributor

@bhishma: please also share the output from Get-PnPException which you can call immediately after the error happens.

@bhishma
Copy link

bhishma commented Jan 29, 2021

@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

@erwinvanhunen
Copy link
Member Author

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?

@bhishma
Copy link

bhishma commented Jan 29, 2021

They are not created. I tried without -Details as well. Same result.

@erwinvanhunen
Copy link
Member Author

erwinvanhunen commented Jan 30, 2021

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.

@bhishma
Copy link

bhishma commented Jan 30, 2021

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.

@erwinvanhunen
Copy link
Member Author

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.

@erwinvanhunen erwinvanhunen transferred this issue from pnp/powershell Jan 30, 2021
@bhishma
Copy link

bhishma commented Jan 30, 2021

Sorry for confusion. I meant to not show the real guid here that's why tried to obfuscate.
The real error shows GUID properly.

@erwinvanhunen
Copy link
Member Author

erwinvanhunen commented Jan 31, 2021

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.

@bhishma
Copy link

bhishma commented Jan 31, 2021

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


@erwinvanhunen
Copy link
Member Author

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'

@jansenbe jansenbe added area: model 📐 Related to the core SDK models question Further information is requested labels Feb 3, 2021
@jansenbe
Copy link
Contributor

jansenbe commented Feb 4, 2021

@bhishma : do you have an update to share?

@bhishma
Copy link

bhishma commented Feb 5, 2021

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.

@erwinvanhunen
Copy link
Member Author

We would propose to exclude the SharePoint tenant from the proxy, but it unfortunately stops here for us as we cannot control your proxy.

@ollimenzel
Copy link

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?!

@rtonerii
Copy link

rtonerii commented Jun 1, 2021

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.

@DaleyKD
Copy link
Contributor

DaleyKD commented Jun 1, 2021

@ollimenzel and @rtonerii : Are you both using the PnP.PowerShell? What version?

I can confirm that this works fine in PnP.Core via C#.

@ollimenzel
Copy link

Hi in the meantime I opened a new report, and it was also reproduceable as you can see here:
pnp/powershell#668
It seems to be a problem with the root SiteCollection in my case

@DaleyKD
Copy link
Contributor

DaleyKD commented Jun 1, 2021

@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 .

@ollimenzel
Copy link

Thanks for helping out!

@jansenbe
Copy link
Contributor

jansenbe commented Jun 2, 2021

@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.

@jansenbe jansenbe reopened this Jun 2, 2021
@rtonerii
Copy link

rtonerii commented Jun 3, 2021

@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.ReadOnlySpan1)'`

@DaleyKD
Copy link
Contributor

DaleyKD commented Jun 3, 2021

@rtonerii : Could you show me your full Add-PnPListItem command you're using? (You can omit the tenant if you'd like.)

@rtonerii
Copy link

rtonerii commented Jun 3, 2021

@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.

@jansenbe
Copy link
Contributor

jansenbe commented Jun 3, 2021

Can you check the PS version where it works (and not works). You get the PS version via $PSVersionTable

@rtonerii
Copy link

rtonerii commented Jun 3, 2021

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

@jansenbe
Copy link
Contributor

jansenbe commented Jun 4, 2021

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

@rtonerii
Copy link

rtonerii commented Jun 5, 2021

I can try both on monday.

@rtonerii
Copy link

rtonerii commented Jun 7, 2021

OK,
The use happens on both versions.

Only on the root site.

@rtonerii
Copy link

rtonerii commented Jun 7, 2021

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.ReadOnlySpan1)'`

Everything works with the regular PowerShell console windows.

@jansenbe
Copy link
Contributor

jansenbe commented Jun 8, 2021

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.

@jansenbe jansenbe closed this as completed Jun 8, 2021
@rtonerii
Copy link

rtonerii commented Jun 8, 2021

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.

@Micael-stack
Copy link

Pnp Powershell is really not working well with Ps 5.1. Switch to Ps7.

With VsCode :
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants