Skip to content

DesiredStateConfiguration module not found #3971

Closed
PowerShell/PowerShellEditorServices
#2062
@EdCallahan

Description

@EdCallahan

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

In some PowerShell project folders, when I use F5 to run debugging, the second time I get the error:

The specified module 'C:\Program Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was
not loaded because no valid module file was found in any module directory.

(Note that that is not the directory that module exists in)

The simples powershell program I have to replicate the problem is:

$ErrorActionPreference = 'Inquire'
$obj = New-Object Ed.NoObject

It only happens when the error action is set to Inquire, it will not happen when set to Stop.

This does not happen to all Powershell project folders. The problem popped up just this week. It has hit me and a coworker. I have been able to replicate the problem on my corporate network and on a laptop off the domain at home.

The problem seems to be related to bad session files. If I find the session file for the folder in C:\Users<username>\AppData\Roaming\Code\User\workspaceStorage and delete it, the problem disappears.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.19041.1645
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1645
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

PS C:\Users\Ed\Documents\Test2> code --version
1.67.1
da15b6fd3ef856477bf6f4fb29ba1b7af717770d
x64

Extension Version

PS C:\Users\Ed\Documents\Test2> code --list-extensions --show-versions | select-string powershell

ms-vscode.powershell@2022.5.1

Steps to Reproduce

  1. Create a new folder and open it with VSCode
  2. Create a debug.ps1 file with the two PowerShell lines above
  3. Close VSCode
  4. Find the session directory in C:\Users<username>\AppData\Roaming\Code\User\workspaceStorage (use the datestamp to find the most recent. Confirm by looking at the workspace.json file in the directory). Overwrite the two state files with the two attached to this message. They are from one of my projects I have the problem with.
  5. Open the folder in VSCode again. Run the debug.ps1 program created in step 2 above twice, using F5

statefiles.zip

Visuals

DSC_Debug.mp4

Logs

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions