[Remove-PnPFolder] throws error "Could not load file or assembly"
Reporting an Issue
Getting a 'Could not load file or assembly' error after updating to latest release.
Expected behavior
Folder is removed; no error thrown; the assembly is loaded from the UNC path where it resides (e.g. \\path\to\home\WindowsPowerShell\...\3.10.1906.0\Newtonsoft.Json.dll)
Actual behavior
Running Remove-PnPFolder results in
Remove-PnPFolder : Could not load file or assembly 'file:///C:\path\to\home\WindowsPowerShell\Modules\SharePointPnPPowerShell2013\3.10.1906.0\NewtonSoft.Json.dll' or one of its dependencies. The system cannot find the file specified. At C:\dev\projects\project\scripts\republish.ps1:24 char:1 + Remove-PnPFolder -Name static -Folder / -Recycle -Force -ErrorAction ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Remove-PnPFolder], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,SharePointPnP.PowerShell.Commands.Files.RemoveFolder
Steps to reproduce behavior
- Install modules to a UNC path
- Run
Connect-PnPOnline - Run
Remove-PnPFolder
Which version of the PnP-PowerShell Cmdlets are you using?
- [x] PnP PowerShell for SharePoint 2013
- [ ] PnP PowerShell for SharePoint 2016
- [ ] PnP PowerShell for SharePoint Online
What is the version of the Cmdlet module you are running?
3.10.1906.0
How did you install the PnP-PowerShell Cmdlets?
- [ ] MSI Installed downloaded from GitHub
- [x] Installed through the PowerShell Gallery with Install-Module -Scope CurrentUser
- [ ] Other means
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Might be a general issue with this release when installed with -Scope CurrentUser. I just got the same error while using the Get-PnPProvisioningTemplate cmdlet:

I've also installed the cmdlets using the CurrentUser scope due to lack of permanent admin privileges.
It is related to -Scope CurrentUser. I get the same error when I update the modules. Installing the msi packages to my local profile works, but is less than optimal. I receive the error running any PnP cmdlet on versions past 3.9.1905.3 related to NewtonSoft.Json.dll.
Any update on this? I am experiencing this issue right now with the module being located in my userprofile which is redirected to a UNC path on the file server

I was able to locate the issue in the master branch code. In the PnPCmdlet.cs file on line 136, the code used to dynamically load the NewtonSoft.Json.dll is not suited to work with UNC paths, so the issue here is not a user profile in general, but may arise when the userprofile is redirected to a file server as the code does not correctly build the path when loaded from a UNC file path.
I was not able to find the issue in the dev branch though, so I am hoping this is going to make it to the next release. For all those of you who cannot wait, there are two workarounds:
Workaround 1:
Place the module on a non-UNC path, e.g. a local path like "C:\temp"
Workaround 2: For all those of you who are able to build the code and module themselves, you can replace the code at line 136 in PnPCmdlet.cs with the following code as a workaround, until the fix is released:
private string AssemblyDirectory
{
get
{
var location = Assembly.GetExecutingAssembly().Location;
var escapedLocation = Uri.UnescapeDataString(location);
return Path.GetDirectoryName(escapedLocation);
}
}
Any update on this? I am getting the below error. I think it is the "My Documents" folder is not enclosed in quote somehow.
PS C:> Set-PnPClientSidePage -Identity $PageName -LayoutType Home Set-PnPClientSidePage : Could not load file or assembly 'file:///C:\users\MYUSER\My Documents\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.16.1912.0\NewtonSoft.Json.dll' or one of its dependencies. The system cannot find the file specified. At line:1 char:1
- Set-PnPClientSidePage -Identity $PageName -LayoutType Home
-
+ CategoryInfo : NotSpecified: (:) [Set-PnPClientSidePage], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,SharePointPnP.PowerShell.Commands.ClientSidePages.SetClientSidePage
This will be fixed in the February 2020 release of PnP PowerShell which is scheduled for Monday January 10, 2020. Closing this issue. Feel free to reopen in case the issue still occurs after the February 2020 version has been released.
@PowershellNinja I think this is causing #2521, which would seem to prevent PnP PowerShell from being used in an Azure Function.
Yes, I'm going to revert it back and to find another solution. Thanks.
Submitted PR #2566 in which this should be fixed