vscode-powershell: DesiredStateConfiguration module not found
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
- Create a new folder and open it with VSCode
- Create a debug.ps1 file with the two PowerShell lines above
- Close VSCode
- 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.
- Open the folder in VSCode again. Run the debug.ps1 program created in step 2 above twice, using F5
Visuals
Logs
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (6 by maintainers)
@andyleejordan Thanks Andy! It is a good compromise. It’s strange that the progress bar disappears for you. I have tried it on 3 different computers, and it stays on in every case. Anyways thanks a lot for a quick fix!
Anyway I silenced it completely in https://github.com/PowerShell/PowerShellEditorServices/pull/2068.
Awesome, thanks for confirming! Looks like it’s loading correctly (finally).
I’m unable to reproduce the error with 2023.9.2 either, as expected but still good news.
A new behavior is some new messaging when running the script, as a result of (finally) successfully loading PSDesiredStateConfiguration I expect. Harmless I think, but just mentioning it since it’s new:
Using the steps in the first post in the issue report, I was able to reproduce the error in Powershell module 2023.6.0. (I had to set a breakpoint in the script before step 5 to get the error).
When I updated to the preview version 2023.9.1 I was not able to reproduce the bug.
I saw the updates that you did yesterday on this section of code, @andyleejordan. Makes a ton of sense to my inexperienced eye, thanks much for the quick action on that. I’ll test again once that code is released as a preview version.
@EdCallahan heh, yeah I agree that’s wonky. I’ll try to fix it. For what it’s worth, we also silenced the warning when DSC isn’t found, can you try the pre-release extension and let me know if it’s still noisy when the module isn’t found?
Thanks for the follow up!
This hasn’t happened to me for a long while, and I don’t find anyone else on the web with the same problem. I’m glad this issue is posted since anyone with the problem will be able to search and find the solution, but it’s probably not worth anyone’s time to debug at this point.