PowerShell / PowerShell/PowerShellEditorServices

Static methods in PSClasses are sometimes marshaled to disposed runspaces

Open
#483 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug
Dominant language
C#
Stars
767
Forks
266
Avg merge
3d 16h
Merged PRs (30d)
1

Description

logs.zip
ReproSteps.zip

Steps to reproduce

  1. Download an extract in the included example.

  2. Move the folder "Example" into your PSModulePath

  3. Open the folder "Example2" in VSCode

  4. Open the file "First.ps1" and run the command Test-Class (this is a function from "Example")

  5. (Optional) Run the command included in "First.ps1", this will show the runspace the static method is currently bound to.

  6. Open the file "Second.ps1" and run the command Test-Class again.

  7. (Optional) Run Get-BoundRunspace again.

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.