Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

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

Closed
2 of 6 tasks
jshowatt opened this issue Jun 12, 2019 · 10 comments
Closed
2 of 6 tasks

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

jshowatt opened this issue Jun 12, 2019 · 10 comments
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.

Comments

@jshowatt
Copy link

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?

  • 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
  • Installed through the PowerShell Gallery with Install-Module -Scope CurrentUser
  • Other means
@ghost
Copy link

ghost commented Jun 12, 2019

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

@ghost ghost added the Needs: Triage 🔍 label Jun 12, 2019
@despingu
Copy link

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.

@jsc627
Copy link

jsc627 commented Aug 6, 2019

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.

@PowershellNinja
Copy link
Contributor

PowershellNinja commented Sep 20, 2019

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
Copy link
Contributor

PowershellNinja commented Oct 2, 2019

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

@UltraGC
Copy link

UltraGC commented Dec 17, 2019

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
    

@KoenZomers
Copy link
Collaborator

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.

@tdwhite0
Copy link

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

@PaoloPia
Copy link
Contributor

PaoloPia commented Mar 6, 2020

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

@KoenZomers
Copy link
Collaborator

Submitted PR #2566 in which this should be fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:fixed-next-drop Issue will be fixed in upcoming release.
Projects
None yet
Development

No branches or pull requests

8 participants