question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update-PSResource tries to reinstall required dependencies

See original GitHub issue

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

Update a module with a required dependency, it is helpful to have a binary module loaded so the files are locked.

Expected behavior

# required module is not installed again

Actual behavior

Update-PSResource anypackage.programs -PassThru
Update-PSResource: Unable to successfully install package 'AnyPackage': 'Cannot remove package path C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1. The previous package contents have been restored.'
Update-PSResource: Operation is not valid due to the current state of the object.

Error details

ErrorIndex: 0

Exception             :
    Type    : System.InvalidOperationException
    Message : Operation is not valid due to the current state of the object.
    HResult : -2146233079
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper
CategoryInfo          : InvalidOperation: (Microsoft.PowerShel…dlets.InstallHelper:InstallHelper) [Update-PSResource],
InvalidOperationException
FullyQualifiedErrorId : InstallPackageTryMoveContentFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.UpdatePSResource
InvocationInfo        :
    MyCommand        : Update-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 1
    Line             : Update-PSResource anypackage.programs -PassThru
    Statement        : Update-PSResource anypackage.programs -PassThru
    PositionMessage  : At line:1 char:1
                       + Update-PSResource anypackage.programs -PassThru
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Update-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :




   ErrorIndex: 1

Exception             :
    Type           : System.Management.Automation.PSInvalidOperationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Unable to successfully install package 'AnyPackage': 'Cannot remove package path
C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1. The previous package contents have been restored.'
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvalidOperation
    Message        : Unable to successfully install package 'AnyPackage': 'Cannot remove package path
C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1. The previous package contents have been restored.'
    InnerException :
        Type           : System.Management.Automation.PSInvalidOperationException
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Cannot remove package path C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1.
The previous package contents have been restored.
                HResult : -2146233087
            CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : InvalidOperation
        TargetSite     :
            Name          : DeleteDirectoryWithRestore
            DeclaringType : Microsoft.PowerShell.PSResourceGet.UtilClasses.Utils, Microsoft.PowerShell.PSResourceGet,
Version=0.5.22.0, Culture=neutral, PublicKeyToken=null
            MemberType    : Method
            Module        : Microsoft.PowerShell.PSResourceGet.dll
        Message        : Cannot remove package path C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1. The
previous package contents have been restored.
        InnerException :
            Type       : System.UnauthorizedAccessException
            TargetSite :
                Name          : DeleteFile
                DeclaringType : System.IO.FileSystem, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e
                MemberType    : Method
                Module        : System.Private.CoreLib.dll
            Message    : Access to the path
'C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1\AnyPackage.dll' is denied.
            Source     : System.Private.CoreLib
            HResult    : -2147024891
            StackTrace :
   at System.IO.FileSystem.DeleteFile(String fullPath)
   at Microsoft.PowerShell.PSResourceGet.UtilClasses.Utils.DeleteDirectory(String dirPath)
   at Microsoft.PowerShell.PSResourceGet.UtilClasses.Utils.DeleteDirectoryWithRestore(String dirPath)
        Source         : Microsoft.PowerShell.PSResourceGet
        HResult        : -2146233079
        StackTrace     :
   at Microsoft.PowerShell.PSResourceGet.UtilClasses.Utils.DeleteDirectoryWithRestore(String dirPath)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper.MoveFilesIntoInstallPath(PSResourceInfo pkgInfo,
Boolean isModule, Boolean isLocalRepo, String dirNameVersion, String tempInstallPath, String installPath, String
newVersion, String moduleManifestVersion, String scriptPath)
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper.TryMoveInstallContent(String tempInstallPath, ScopeType
scope, Hashtable packagesHash)
    HResult        : -2146233079
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.UpdatePSResource
CategoryInfo          : InvalidOperation: (Microsoft.PowerShel…ts.UpdatePSResource:UpdatePSResource)
[Update-PSResource], PSInvalidOperationException
FullyQualifiedErrorId : InstallPackageFailed,Microsoft.PowerShell.PSResourceGet.Cmdlets.UpdatePSResource
InvocationInfo        :
    MyCommand        : Update-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 1
    Line             : Update-PSResource anypackage.programs -PassThru
    Statement        : Update-PSResource anypackage.programs -PassThru
    PositionMessage  : At line:1 char:1
                       + Update-PSResource anypackage.programs -PassThru
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Update-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

beta22

Visuals

No response

Issue Analytics

  • State:closed
  • Created 2 months ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ThomasNietocommented, Jul 18, 2023

@SydneyhSmith here is another example with more detailed reproduction.

PS C:\> Find-PSResource anypackage

Name       Version Prerelease Repository Description
----       ------- ---------- ---------- -----------
AnyPackage 0.5.1              PSGallery  Use various package managers with a single set of commands.

PS C:\> Get-InstalledPSResource anypackage

Name       Version Prerelease Repository Description
----       ------- ---------- ---------- -----------
AnyPackage 0.5.1              PSGallery  Use various package managers with a single set of commands.
AnyPackage 0.4.1              PSGallery  Use various package managers with a single set of commands.
AnyPackage 0.4.0              PSGallery  Use various package managers with a single set of commands.
AnyPackage 0.3.0              PSGallery  Use various package managers with a single set of commands.
AnyPackage 0.2.0              PSGallery  Use various package managers with a single set of commands.
AnyPackage 0.1.2              PSGallery  Use various package managers with a single set of commands.
AnyPackage 0.1.0              PSGallery  Use various package managers with a single set of commands.

PS C:\> Update-PSResource AnyPackage.Msu -PassThru
Update-PSResource: Unable to successfully install package 'AnyPackage': 'Cannot remove package path C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1. The previous package contents have been restored.'
Update-PSResource: Operation is not valid due to the current state of the object.
PS C:\> Get-InstalledPSResource anypackage.Msu

Name           Version Prerelease Repository Description
----           ------- ---------- ---------- -----------
AnyPackage.Msu 0.2.3              PSGallery  Windows Msu provider for AnyPackage.
AnyPackage.Msu 0.2.2              PSGallery  Windows Msu provider for AnyPackage.

PS C:\> Find-PSResource anypackage.msu

Name           Version Prerelease Repository Description
----           ------- ---------- ---------- -----------
AnyPackage.Msu 0.3.0              PSGallery  Windows Msu provider for AnyPackage.

PS C:\> Update-PSResource AnyPackage.Msu -PassThru
Update-PSResource: Unable to successfully install package 'AnyPackage': 'Cannot remove package path C:\Users\Thomas\Documents\PowerShell\Modules\AnyPackage\0.5.1. The previous package contents have been restored.'
Update-PSResource: Operation is not valid due to the current state of the object.
PS C:\> Get-InstalledPSResource anypackage.Msu

Name           Version Prerelease Repository Description
----           ------- ---------- ---------- -----------
AnyPackage.Msu 0.2.3              PSGallery  Windows Msu provider for AnyPackage.
AnyPackage.Msu 0.2.2              PSGallery  Windows Msu provider for AnyPackage.

PS C:\> Update-PSResource AnyPackage.Msu -PassThru -SkipDependencyCheck

Name           Version Prerelease Repository Description
----           ------- ---------- ---------- -----------
AnyPackage.Msu 0.3.0              PSGallery  Windows Msu provider for AnyPackage.
0reactions
anamnavicommented, Jul 25, 2023

Was fixed by PR #1255 I believe

Read more comments on GitHub >

github_iconTop Results From Across the Web

When installing an R package, automatically reinstall ...
utils::install.packages seems to be perfectly capable of installing dependencies that are missing. But if there's a dependency that's already ...
Read more >
Fix: Couldn't install dependency error | Valorant Guide
Want to play Valorant, but receiving an error about needing to contact support to fix a dependency error? Well, this video covers the...
Read more >
Couldn't install Required Dependency
Hey, so I've been trying to install vanguard for the past two-three weeks-ish and everytime I try to install it, it keeps giving...
Read more >
How to install only the dependencies of a package?
To install dependencies only, you can use apt-cache show package | grep Depends . This will give you a list of dependencies:
Read more >
Problem installing suggested remote dependency ...
It seems that the Remotes section is being ignored and that it is trying to install the dependency from CRAN and thus fails....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found