PnP-PowerShell icon indicating copy to clipboard operation
PnP-PowerShell copied to clipboard

[Remove-PnPFolder] throws error "Could not load file or assembly"

Open bensmuda opened this issue 7 years ago • 10 comments

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

  1. Install modules to a UNC path
  2. Run Connect-PnPOnline
  3. 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

bensmuda avatar Jun 12 '19 21:06 bensmuda

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar Jun 12 '19 21:06 ghost

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: image

I've also installed the cmdlets using the CurrentUser scope due to lack of permanent admin privileges.

despingu avatar Jun 17 '19 13:06 despingu

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.

jsc627 avatar Aug 06 '19 13:08 jsc627

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

image

PowershellNinja avatar Sep 20 '19 12:09 PowershellNinja

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);
            }
        }

PowershellNinja avatar Oct 02 '19 13:10 PowershellNinja

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
    

UltraGC avatar Dec 17 '19 00:12 UltraGC

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.

KoenZomers avatar Feb 06 '20 22:02 KoenZomers

@PowershellNinja I think this is causing #2521, which would seem to prevent PnP PowerShell from being used in an Azure Function.

tdwhite0 avatar Feb 18 '20 20:02 tdwhite0

Yes, I'm going to revert it back and to find another solution. Thanks.

PaoloPia avatar Mar 06 '20 16:03 PaoloPia

Submitted PR #2566 in which this should be fixed

KoenZomers avatar Mar 07 '20 00:03 KoenZomers