PowerShell / PowerShell/PowerShellEditorServices
Static methods in PSClasses are sometimes marshaled to disposed runspaces
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 767
- Forks
- 266
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
Steps to reproduce
-
Download an extract in the included example.
-
Move the folder "Example" into your PSModulePath
-
Open the folder "Example2" in VSCode
-
Open the file "First.ps1" and run the command
Test-Class(this is a function from "Example") -
(Optional) Run the command included in "First.ps1", this will show the runspace the static method is currently bound to.
-
Open the file "Second.ps1" and run the command
Test-Classagain. -
(Optional) Run
Get-BoundRunspaceagain.
Expected results
The command Test-Class to output Test was successful both times, and Get-BoundRunspace to return the current default runspace both times.
Actual results
The command Test-Class works the first time, but after the second file is opened it throws a null reference exception and Get-BoundRunspace shows a runspace that is no longer open.
Notes
The steps are exact, if Test-Class isn't ran before switching files, or if "Second.ps1" is loaded first, it won't happen.
Although the steps may seem strange, this happens to me frequently if my module is in the module path, and makes static methods in classes not viable. My assumption is that PSES creates a runspace for PSSA which then loads the module causing that execution context to be the new owner. The runspace is then disposed, but the owner doesn't revert.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ReproSteps.zip and logs.zip, then follow the listed Test-Class and Get-BoundRunspace steps while tracing static-method runspace ownership across First.ps1 and Second.ps1. Done means the command succeeds on both runs and Get-BoundRunspace reports the current default runspace rather than a disposed one.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell, vscode
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100