Taco_Buffet
Taco_Buffet

Reputation: 236

Unable to Use SharePoint PNP PowerShell in VSCode

Running this command in VScode doesn't work but it works in PowerShellPlus.

Connect-PnPOnline -Url "https://something.sharepoint.com/" -Credentials $userCredential

Error:

   System.MissingMethodException: Method not found: 'System.Runtime.Remoting.ObjectHandle System.Activator.CreateInstance(System.String, System.String)'.
   at SharePointPnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()

I've tried uninstalling VScode and removing any trace of SharePoint my machine but I'm not able to get past this error. Any ideas?

Edit: Following this blog post, I removed and reinstalled the SP PNP module. https://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=802

  1. Delete all the SharePoint Components from the Control Panel (Add/Remove)
  2. Open the GAC location (C:\windows\Microsoft.NET\assembly\GAC_MSIL), search for the term SharePoint and delete all the folders. (This is required since the reference is still old which is used by the PnP commands)
  3. Re-Start the machine
  4. Install the latest version of the SharePoint PnP

Upvotes: 1

Views: 2765

Answers (2)

Taco_Buffet
Taco_Buffet

Reputation: 236

Here is how I fixed my issue:
1. In VSCode open the Command Palette on Windows or Linux with Ctrl+Shift+P. On macOS, use Cmd+Shift+P.
2. Search for Session.
3. Click on PowerShell: Show Session Menu.
4. Choose one of the ___ (x86) options

I was using x64 and that clearly didn't work.

Upvotes: 3

Jerry
Jerry

Reputation: 3615

Please don't uninatll the SharePoint trace in your machine and make sure you have install the corresponding PnP PowerShell library:

SharePoint/PnP-PowerShell

Then in VSCode, please install the PowerShell plugin:

enter image description here

Open the .ps1 which saved PnP PowerShell code and press F5 to run and debug:

enter image description here enter image description here

Upvotes: 0

Related Questions