Skip to content

Cache entry path not found #495

@Gijsreyn

Description

@Gijsreyn

Prerequisites

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

Summary

Whenever a user removes a module from the $env:PSMODULEPATH and the caching was already done, an error is thrown:

Get-Item: Cannot find path 'C:\Program Files\PowerShell\Modules\Microsoft.WinGet.DSC\1.8.1911\Microsoft.WinGet.DSC.psd1' because
it does not exist.
InvalidOperation: You cannot call a method on a null-valued expression.

Get-Item cannot operate on null values. Would it be better to change this:

if (-not ((Get-Item $_.Name).LastWriteTime.Equals([DateTime]$_.Value)))
{
    "Detected stale cache entry '$($_.Name)'" | Write-DscTrace
    $refreshCache = $true
    break
}

To:

if ($_.Name) 
{
  if (-not ((Get-Item $_.Name).LastWriteTime.Equals([DateTime]$_.Value)))
  {
      "Detected stale cache entry '$($_.Name)'" | Write-DscTrace
      $refreshCache = $true
      break
  }
}

Steps to reproduce

  1. Install Microsoft.WinGet.DSC
  2. Execute dsc resource list --adapter Microsoft.DSC/PowerShell
  3. Remove Microsoft.WinGet.DSc
  4. Execute dsc resource list --adapter Microsoft.DSC/PowerShell once more

No data is returned.

Expected behavior

Returned list of PowerShell resources

Actual behavior

Nothing happens

Error details

Get-Item: Cannot find path 'C:\Program Files\PowerShell\Modules\Microsoft.WinGet.DSC\1.8.1911\Microsoft.WinGet.DSC.psd1' because
it does not exist.
InvalidOperation: You cannot call a method on a null-valued expression.

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

dsc 3.0.0-preview.8

Visuals

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions