powershell icon indicating copy to clipboard operation
powershell copied to clipboard

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

Open ingepepe opened this issue 3 years ago • 26 comments

  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?

  • [x] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

ingepepe avatar May 26 '21 20:05 ingepepe

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?

YuriySamorodov avatar May 26 '21 23:05 YuriySamorodov

Just did. Same error.

Sent from my iPhone

On May 26, 2021, at 17:10, Yuriy Samorodov @.***> wrote:



Hi @ingepepehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fingepepe&data=04%7C01%7C%7Cb79d1e16f86f40a06f8308d9209b7886%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637576674376873496%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Y6MBIv8g1kKm4e4dUlTT3yvtSvpkdbZldceeQuj5vYo%3D&reserved=0 , 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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpnp%2Fpowershell%2Fissues%2F727%23issuecomment-849178632&data=04%7C01%7C%7Cb79d1e16f86f40a06f8308d9209b7886%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637576674376883492%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=hHCc7xwOxnAXjz3syDKLEKb32%2Bj0NQWroylMNYuWAQM%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAN35QEGWDMLIJS3JR7ZTNBTTPV5WXANCNFSM45S2DGLQ&data=04%7C01%7C%7Cb79d1e16f86f40a06f8308d9209b7886%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637576674376893486%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=o%2Fl9tXrtAD%2BpriZQMx1jSZeFxTE5BnER%2FVSqPg6F%2FBM%3D&reserved=0.

ingepepe avatar May 26 '21 23:05 ingepepe

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.

YuriySamorodov avatar May 26 '21 23:05 YuriySamorodov

I’m using Connect-PnPonline to the source site Ran get-pnplist to make sure I was there

Sent from my iPhone

On May 26, 2021, at 17:23, Yuriy Samorodov @.***> wrote:



Hey @ingepepehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fingepepe&data=04%7C01%7C%7C0ce7359898a44cc0a25c08d9209d56d6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637576682393319031%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Q%2BioCcjvsXAfW%2FAs0NXXYy6kA1xlVTuBUElSyCAHQDQ%3D&reserved=0 , could you please confirm endpoint you are connecting to? Please note you have to connect to source site to move files and folders.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpnp%2Fpowershell%2Fissues%2F727%23issuecomment-849184049&data=04%7C01%7C%7C0ce7359898a44cc0a25c08d9209d56d6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637576682393329031%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=AA%2FzCFQCYdJJyZrga%2FAJbXosu%2BFh1WISeHY%2FJTNrk2E%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAN35QEA64NGUNA72KRQWPULTPV7I5ANCNFSM45S2DGLQ&data=04%7C01%7C%7C0ce7359898a44cc0a25c08d9209d56d6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637576682393329031%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Xh8JIBI3F9Ko2kaYKLh%2FcBC%2BRQsI%2F8DQwDJazMZ8jDA%3D&reserved=0.

ingepepe avatar May 27 '21 00:05 ingepepe

@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 avatar May 27 '21 11:05 veronicageek

@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<Byte>)'. 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 avatar May 27 '21 14:05 ingepepe

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

ingepepe avatar May 27 '21 15:05 ingepepe

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

veronicageek avatar May 28 '21 08:05 veronicageek

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?

colonelclaypoo avatar May 28 '21 09:05 colonelclaypoo

I tried and it worked on PowerShell for Windows (5.1)

Sent from my iPhone

On May 28, 2021, at 03:55, colonelclaypoo @.***> wrote:



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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpnp%2Fpowershell%2Fissues%2F727%23issuecomment-850300946&data=04%7C01%7C%7Cb1875a6bdb364e10285c08d921beb40c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637577925272385607%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=hf0oRRRk%2B%2FsNsl9H67olDswMT9%2BN0tf4K%2FnWKruWMtI%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAN35QEGZBSIIELIUWFPIYULTP5SAPANCNFSM45S2DGLQ&data=04%7C01%7C%7Cb1875a6bdb364e10285c08d921beb40c%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637577925272385607%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IG14grLaqAqrh8AOhHR9p40uX54wrQLi6VnXenvNUwI%3D&reserved=0.

ingepepe avatar May 28 '21 13:05 ingepepe

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

github-actions[bot] avatar Jun 12 '21 02:06 github-actions[bot]

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.

SergeiAtML avatar Jun 15 '21 13:06 SergeiAtML

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.

colonelclaypoo avatar Jun 15 '21 14:06 colonelclaypoo

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

jpwegmuller50 avatar Jun 23 '21 18:06 jpwegmuller50

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'

RoSchoe avatar Jul 27 '21 09:07 RoSchoe

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

mcihon-inwk avatar Aug 06 '21 18:08 mcihon-inwk

Same with Move-PnPFile :) VS Code 1.59

RoSchoe avatar Aug 09 '21 06:08 RoSchoe

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<Byte>)".

Maybe "System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1<Byte>)" 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.

Tom-CK avatar Aug 18 '21 11:08 Tom-CK

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: https://github.com/PowerShell/vscode-powershell/issues/3510

andyleejordan avatar Sep 28 '21 20:09 andyleejordan

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.

erkanch avatar Sep 30 '21 00:09 erkanch

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.

Azaama avatar Oct 06 '21 22:10 Azaama

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 avatar Oct 07 '21 10:10 martinlingstuyl

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)

martinlingstuyl avatar Oct 07 '21 10:10 martinlingstuyl

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

andyleejordan avatar Oct 07 '21 17:10 andyleejordan

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.

gautamdsheth avatar Oct 07 '21 19:10 gautamdsheth

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?

andyleejordan avatar Oct 07 '21 19:10 andyleejordan

@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 avatar Mar 24 '23 14:03 gautamdsheth

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.

gautamdsheth avatar Apr 05 '23 13:04 gautamdsheth