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

[BUG] VSCode Move-PnPFile : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1)'. #727

Closed
1 of 6 tasks
ingepepe opened this issue May 26, 2021 · 28 comments

Comments

@ingepepe
Copy link

  1. Are you using Invoke-PnPSiteTemplate or Get-PnPSiteTemplate?
    No

Reporting an Issue or Missing Feature

When trying to execute the command

Move-PnPFile -SourceUrl "/sites/Leadership-365/Shared Documents/Regional Managers" -TargetUrl "/sites/operations.leaders/Shared Documents" -AllowSchemaMismatch

I get the following error:

Move-PnPFile : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1)'.

What is this error about?

Expected behavior

Run the cmdlet

Actual behavior

Error: Method not Found

Steps to reproduce behavior

When trying to execute the command

Move-PnPFile -SourceUrl "/sites/Leadership-365/Shared Documents/Regional Managers" -TargetUrl "/sites/operations.leaders/Shared Documents" -AllowSchemaMismatch

I get the following error:

Move-PnPFile : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1)'.

What is the version of the Cmdlet module you are running?

(you can retrieve this by executing Get-Module -Name "PnP.PowerShell" -ListAvailable)

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.5.38     PnP.PowerShell                      {Add-PnPAlert, Add-PnPApp, Add-PnPApplicationCustomizer, Add-PnPAzureADGroupMember...}

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@ingepepe ingepepe added the bug Something isn't working label May 26, 2021
@YuriySamorodov
Copy link
Contributor

Hi @ingepepe , could you please update module? We are already on PnP,PowerShell 1.5.54
Personally I am not able to replicate that issue even on PnP.PowerShell 1.5.42

Could you please also update Title of this request to better reflect the problem?

@ingepepe
Copy link
Author

ingepepe commented May 26, 2021 via email

@YuriySamorodov
Copy link
Contributor

Hey @ingepepe , could you please confirm endpoint you are connecting to? Please note you have to connect to source site to move files and folders.

@ingepepe
Copy link
Author

ingepepe commented May 27, 2021 via email

@veronicageek
Copy link
Collaborator

@ingepepe - I'm using 1.5.55-nightly and have no issue. Please update the module and try again, or try another site.

Also, what is that dot (.) in your target site?

@veronicageek veronicageek removed the bug Something isn't working label May 27, 2021
@ingepepe ingepepe changed the title [BUG] [BUG] Move-PnPFile : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1)'. May 27, 2021
@ingepepe
Copy link
Author

@veronicageek

This is what I get from another site:

VERBOSE: PnP PowerShell Cmdlets (1.5.54.0)
PS C:> Move-PnPFile -SourceUrl "/sites/test01/lead/Team Meetings/MyFile.docx" -TargetUrl "/sites/test02/Shared Documents/General" -NoWait -Force -AllowSchemaMismatch -AllowSmallerVersionLimitOnDestination

Move-PnPFile : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1)'.
At line:1 char:1

  • Move-PnPFile -SourceUrl "/sites/test01/lead/Team Meetings/MyFile.docx ...
  •   + CategoryInfo          : WriteError: (:) [Move-PnPFile], MissingMethodException
      + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Files.MoveFile
    

@ingepepe
Copy link
Author

Not sure if it has to do with the fact that I'm executing it from VS Code?

@ingepepe ingepepe changed the title [BUG] Move-PnPFile : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1)'. [BUG] VSCode Move-PnPFile : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1)'. May 27, 2021
@veronicageek
Copy link
Collaborator

@ingepepe - I don't think VSCode is not an issue as I've been able to successfully run your code.
I'm still not able to reproduce unfortunately and it's working fine for me.

Let's see if @gautamdsheth / @erwinvanhunen have any ideas / insights.

@colonelclaypoo
Copy link

I've been experiencing a similar issue with a for example Add-PnPPage. In VSCode I'm getting:
Method not found: "System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1<Boolean> Enumerator.MoveNextAsync()"

Using 1.5.55-nightly.

It works fine in PowerShell 5 and 7 standalone console.

So it might be VSCode related after all what do you think?

@ingepepe
Copy link
Author

ingepepe commented May 28, 2021 via email

@github-actions
Copy link

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

@SergeiAtML
Copy link

SergeiAtML commented Jun 15, 2021

I had the same exact issue with different command-lets. Ended up downgrading to 1.5.0 and issue went away. What was really strange that I did not have any issues running it from powershell prompt or PS ISE.

@colonelclaypoo
Copy link

It's unfortunate but I can confirm your two statements @SergeiAtML. Ended up downgrading as well on one machine end try to use the PowerShell 7 default shell when necessarily have to make use of a newer version than 1.5.0.

@jpwegmuller50
Copy link

I can also confirm that downgrading to 1.5.0 resolves the issue in VSCode (mine was with the Add-PnPGroupMember cmdlet).

@RoSchoe
Copy link

RoSchoe commented Jul 27, 2021

What has been done in 1.6.0 / 1.7.0 from 1.5.0 with the
.net library or sth?

downgrade to 1.5.0 solved it - but why?
Without vscode in ise all is fine.

Same if you want to add a security group by id to a communication site
Add-PnPGroupMember -Group $spGroupVisitor -LoginName 'c:0t.c|tenant|b6bfb989-98cd-4fcb-95e0-5be17b7bbac0'

@mcihon-inwk
Copy link

Also ran into this issue with Copy-PnPFile and VSCode. Works fine if run outside of VSCode.

@RoSchoe
Copy link

RoSchoe commented Aug 9, 2021

Same with Move-PnPFile :)
VS Code 1.59

@Tom-CK
Copy link

Tom-CK commented Aug 18, 2021

I am having the same issue using Get-PNPListItem in vscode.
The error does not exist when running Get-PNPListItem in regular PowerShell.

Steps to reproduce:

  • Install-Module PNP.PowerShell -Required Version 1.7.0
    When running Get-PNPListItem in vscode an exception is thown:
    System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. --->
    System.MissingMethodException:
    Methode nicht gefunden: "Int32
    System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1)".

Maybe "System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1)" indicates a type-mismatch in source-code somewhere ?

I then call Uninstall-Module PNP.PowerShell followed by Install-Module PNP.PowerShell -RequiredVersion 1.5.0.
After this, evertything works fine, no error vscode.

So it seems like the error does not exist in PNP.PowerShell 1.5.0 but in version 1.7.0.
And it is only thrown usin vscode powershell.

@andyleejordan
Copy link

Repeating ping but over here...

@KoenZomers and @gautamdsheth are you two also looking at this? It seems to have been introduced when a custom ALC with a resolver was added to PNP.PowerShell, and it's not expecting another ALC (the one in Editor Services) to exist and possibly resolve dependencies. But we're still not entirely sure.

See: PowerShell/vscode-powershell#3510

@erkanch
Copy link

erkanch commented Sep 30, 2021

Try running it in regular VS Code terminal, not in the PowerShell Integrated Console. I had a similar issue with Add-PnPApp and it works on the regular terminal. If you check the versions of the 2 consoles running Get-Host | Select-Object Version, regular console is 5.1.18362.1801, whereas the PowerShell Integrated Console is 2021.9.0.

@Azaama
Copy link

Azaama commented Oct 6, 2021

Hi,

I started having the same issue on Set-PnPListItem after upgrading to 1.7.0 on a regular PS console.
Set-PnPListItem : Method not found : 'Void Microsoft.SharePoint.Client.ListItem.SetComplianceTag

Downgrading to 1.6.0 solves the issue.

@martinlingstuyl
Copy link
Contributor

I'm having the same issue with Add-PnPGroupMember (PnP PowerShell 1.7.0) in vs code (1.60.2) Integrated Terminal.

Add-PnPGroupMember : Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1<Byte>)'

Issue 'solved' when running the command from Windows Terminal > PowerShell Window

@martinlingstuyl
Copy link
Contributor

Try running it in regular VS Code terminal, not in the PowerShell Integrated Console. I had a similar issue with Add-PnPApp and it works on the regular terminal. If you check the versions of the 2 consoles running Get-Host | Select-Object Version, regular console is 5.1.18362.1801, whereas the PowerShell Integrated Console is 2021.9.0.

Running $PSVersionTable will show the same Powershell version though. (In vscode terminal / vscode integrated terminal / windows terminal)

@andyleejordan
Copy link

I think we have tracked this down to a broken scenario where PnP-PowerShell requests a dependency of a different version than the Code extension's Editor Services PowerShell module. With PowerShell Core, this isn't a problem because of the isolated assembly load contexts; however, when using Windows PowerShell (AKA PowerShell 5.1), the existence of the .NET Framework's GAC causes this bug. I am unsure if there's a solution (the "work-around" is to use the modern PowerShell 7 which utilizes .NET Core's assembly load contexts to prevent these kinds of bugs).

@gautamdsheth
Copy link
Collaborator

Yeah PS7 is the way to go. Not sure we can do anything from our side here. If you have any ideas , please let us know. Happy to fix it.

But as long as it works in PS7 and PS5, it should cover majority of the scenarios.

We ran into some trouble because of Az module issues, tried to fix it but looks like that broke VS code executions.

@andyleejordan
Copy link

Theoretically if PnP.PowerShell updated the troublesome dependenc(ies) to the same version that Editor Services uses, it would work, but that's a fragile fix because it's starting to look like there's more than one assembly at play.

In short: these bugs are due to the GAC. The problem was fixed with .NET Core. Windows PowerShell by definition is not PowerShell Core and therefore does not use .NET Core, but the desktop .NET Framework, where the GAC still reigns supreme. Unless someone knows a workaround with the GAC, I think we're up a creek without a paddle for this scenario. @rjmholt would you concur?

@gautamdsheth
Copy link
Collaborator

@andschwa , @ingepepe - we have updated quite a few dependencies in the latest nightly builds as part of prep for an upcoming v2, maybe it fixes the issue ?

To test it, you can download the latest nightly builds and maybe let us know if the issue still persists ?
The v2 supports only PowerShell 7.2 or later versions .

@gautamdsheth
Copy link
Collaborator

Closing this issue now.
Since v2.1.1 , PnP PowerShell is fully on .NET 6, so we have dropped support for PS5.1 or ISE.
If the issue still exists, please feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests