Skip to content

DesiredStateConfiguration module not found #3971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
EdCallahan opened this issue May 12, 2022 · 15 comments · Fixed by PowerShell/PowerShellEditorServices#2062
Closed
6 tasks done

DesiredStateConfiguration module not found #3971

EdCallahan opened this issue May 12, 2022 · 15 comments · Fixed by PowerShell/PowerShellEditorServices#2062
Assignees
Labels

Comments

@EdCallahan
Copy link

EdCallahan commented May 12, 2022

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

[email protected]

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

@EdCallahan EdCallahan added the Issue-Bug A bug to squash. label May 12, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label May 12, 2022
@billsoranno
Copy link

I am experiencing this issue also on version 1.59.0:
Version: 1.59.0 (user setup)
Commit: 379476f0e13988d90fab105c5c19e7abc8b1dea8
Date: 2021-08-04T23:13:12.822Z
Electron: 13.1.7
Chrome: 91.0.4472.124
Node.js: 14.16.0
V8: 9.1.269.36-electron.0
OS: Windows_NT x64 10.0.19044

@EdCallahan
Copy link
Author

EdCallahan commented May 12, 2022

I have found that in every case I've tried so far, if I run into this problem in a folder it goes away if I restart the terminal in vscode and then remove all the breakpoints. This is easier than finding and deleting the session directory.

@SydneyhSmith
Copy link
Collaborator

Thanks so much for the detailed bug report-- it is very helpful for us! We are looking into this issue, but as a temporary workaround using a different $ErrorActionPreference may help since it sounds like this only reproduces with "Inquire", let us know if you hit this with other variables (it may with any preference that causes termination)

@SydneyhSmith SydneyhSmith added Area-Debugging and removed Needs: Triage Maintainer attention needed! labels May 17, 2022
@EdCallahan
Copy link
Author

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.

@andyleejordan
Copy link
Member

Thanks for the follow up!

@EdCallahan EdCallahan reopened this Sep 7, 2023
@EdCallahan
Copy link
Author

EdCallahan commented Sep 7, 2023

I am re-opening this since it turns out I continue to have the problem. I don't know what prompts it, and I'm having a hard time figuring out how I'm fixing it. However, I think I've found where the problem is in the source code.

The error I see is:

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.

The PSDesiredStateConfigure module does not exist in C:\Program Files, it exists in C:\Windows\system32\WindowsPowerShell\v1.0\Modules on my system.

The wrong path is hardcoded in line 96 of https://github.com/PowerShell/PowerShellEditorServices/blob/main/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs

Seems like the $env:PSModulePath should be searched instead of hard-coding a path? Looks like the intent was for errors to be ignored here, but in some situations they aren't, it seems.

I was led to this looking at a similar bug report at #575

@andyleejordan

@andyleejordan
Copy link
Member

@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?

@EdCallahan
Copy link
Author

EdCallahan commented Sep 8, 2023

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?

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

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:

image

@andyleejordan
Copy link
Member

Awesome, thanks for confirming! Looks like it's loading correctly (finally).

@kborowinski
Copy link

@andyleejordan This is very disruptive when using interactive session with PowerShell 5.1:

  1. Press F5 to start interactive session
  2. The PSDesiredStateConfiguration module progress bar shows up and stays on after module import. This completely covers the terminal window
  3. Need to press Enter to make the progress bar disappear but this causes the interactive session to stop
  4. Press F5 again to start interactive session

I've made short gif of how disruptive this is:
Animation

@andyleejordan
Copy link
Member

Oh I see...ok I guess one of three things needs to happen:

  1. We stop imported the DSC module. Considering it was broken and not importing for years, it seems likely whatever functionality it was powering wouldn't be missed.
  2. We import it optionally if that functionality would actually be missed.
  3. We keep importing it automatically but manage to hide this disruptive progress bar.

@SeeminglyScience do you know the history behind the "DSC Breakpoints" stuff?

@andyleejordan
Copy link
Member

@kborowinski FWIW when I try to repro this I do see the progress bar, but then it disappears automatically.

@andyleejordan
Copy link
Member

Anyway I silenced it completely in PowerShell/PowerShellEditorServices#2068.

@kborowinski
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants