Skip to content

fix: PowerShell.Create(Runspace) has no such overload on PS 5.1 - #501

Merged
HeyItsGilbert merged 1 commit into
mainfrom
fix/koan-runspace-ps51-create
Sep 19, 2026
Merged

HeyItsGilbert merged 1 commit into
mainfrom
fix/koan-runspace-ps51-create

Conversation

@HeyItsGilbert

Copy link
Copy Markdown
Member

Summary

[System.Management.Automation.PowerShell]::Create(Runspace) has no such overload on Windows PowerShell 5.1 — its System.Management.Automation assembly (v3.0.0.0, GAC-loaded) only exposes Create(), Create(RunspaceMode), and Create(InitialSessionState). The single-Runspace-argument overload was added later. Calling it with a runspace argument throws:

MethodException: Cannot find an overload for "Create" and the argument count: "1".

This breaks New-KoanRunspace, and transitively Invoke-Koan and anything that calls it (Get-Karma, etc.) on Windows PowerShell 5.1.

Fix

Split the call into [powershell]::Create() followed by assigning the writable .Runspace property, which works identically on PS 5.1 and 7+. Fixed all three sites using the broken pattern:

  • PSKoans/Private/New-KoanRunspace.ps1
  • PSKoans/Private/Invoke-Koan.ps1
  • Tests/Functions/Private/New-KoanRunspace.Tests.ps1 (the test itself used the same broken call)

Verification

Built the module and ran the actual affected Pester suites against the built output:

  • Windows PowerShell 5.1 (powershell.exe): New-KoanRunspace.Tests.ps1 + Invoke-Koan.Tests.ps1 — 7/7 passed (previously threw the MethodException above).
  • pwsh 7: same two files + Get-Karma.Tests.ps1 — 23/23 passed.

Copilot AI lite review requested due to automatic review settings September 18, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved issues were identified, and compatibility was verified across PowerShell 5.1 and 7.

Pull request overview

Fixes PowerShell runspace creation compatibility with Windows PowerShell 5.1.

Changes:

  • Replaces unsupported Create(Runspace) calls with Create() plus .Runspace assignment.
  • Updates the affected test setup.
  • Verified on PowerShell 5.1 and 7.
File summaries
File Description
Tests/Functions/Private/New-KoanRunspace.Tests.ps1 Updates test setup to use the supported API.
PSKoans/Private/New-KoanRunspace.ps1 Creates and assigns the runspace compatibly.
PSKoans/Private/Invoke-Koan.ps1 Uses the compatible runspace assignment pattern.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@HeyItsGilbert
HeyItsGilbert changed the base branch from main to build/reusable-ci-workflow September 18, 2026 23:28
@HeyItsGilbert
HeyItsGilbert force-pushed the fix/koan-runspace-ps51-create branch from eb21735 to 05ec4f6 Compare September 18, 2026 23:30
@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown

Test Results

    4 files  ±0    104 suites  ±0   1m 32s ⏱️ -9s
1 544 tests ±0  1 520 ✅ +13  24 💤 ±0  0 ❌  - 13 
2 964 runs  ±0  2 932 ✅ +13  32 💤 ±0  0 ❌  - 13 

Results for commit 0186e32. ± Comparison against base commit 2a696a6.

This pull request removes 30 and adds 30 tests. Note that renamed tests count towards both.
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/Invoke-Koan.ps1'; Length=3091; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/New-KoanRunspace.ps1'; Length=1420; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/Invoke-Koan.ps1'; Length=3091; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/New-KoanRunspace.ps1'; Length=1420; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/tests/Functions/Private/New-KoanRunspace.Tests.ps1'; Length=2128; Name='New-KoanRunspace.Tests.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/Invoke-Koan.ps1'; Length=3091; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/New-KoanRunspace.ps1'; Length=1420; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/Invoke-Koan.ps1'; Length=3091; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/New-KoanRunspace.ps1'; Length=1420; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/tests/Functions/Private/New-KoanRunspace.Tests.ps1'; Length=2128; Name='New-KoanRunspace.Tests.ps1'}
…
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/Invoke-Koan.ps1'; Length=3119; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/New-KoanRunspace.ps1'; Length=1440; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/Invoke-Koan.ps1'; Length=3119; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/New-KoanRunspace.ps1'; Length=1440; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has exactly one line feed at EOF in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/tests/Functions/Private/New-KoanRunspace.Tests.ps1'; Length=2152; Name='New-KoanRunspace.Tests.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/Invoke-Koan.ps1'; Length=3119; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/Output/PSKoans/0.67.0/Private/New-KoanRunspace.ps1'; Length=1440; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/Invoke-Koan.ps1'; Length=3119; Name='Invoke-Koan.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/PSKoans/Private/New-KoanRunspace.ps1'; Length=1440; Name='New-KoanRunspace.ps1'}
/Users/runner/work/PSKoans/PSKoans/tests/ModuleValidation.Tests.ps1 ‑ Static Analysis: Module & Repository Files.Repository Code.has no invalid syntax errors in IO.FileInfo{FullName='/Users/runner/work/PSKoans/PSKoans/tests/Functions/Private/New-KoanRunspace.Tests.ps1'; Length=2152; Name='New-KoanRunspace.Tests.ps1'}
…

♻️ This comment has been updated with latest results.

@HeyItsGilbert
HeyItsGilbert added this pull request to stack #502 September 18, 2026 23:42
Base automatically changed from build/reusable-ci-workflow to main September 19, 2026 18:00
[System.Management.Automation.PowerShell]::Create(Runspace) doesn't
exist as an overload in Windows PowerShell 5.1's System.Management.
Automation (v3.0.0.0, GAC-loaded) -- only Create(), Create(RunspaceMode),
and Create(InitialSessionState) are available there. Calling it with a
Runspace argument throws:

  MethodException: Cannot find an overload for "Create" and the
  argument count: "1".

Split into Create() followed by assigning the writable Runspace
property instead, which works on both PS 5.1 and 7+.

Fixes both call sites (New-KoanRunspace and Invoke-Koan) plus the
test file's own use of the same broken pattern.

Verified locally: New-KoanRunspace.Tests.ps1 + Invoke-Koan.Tests.ps1
pass under both powershell.exe 5.1 and pwsh 7.
@HeyItsGilbert
HeyItsGilbert force-pushed the fix/koan-runspace-ps51-create branch from 05ec4f6 to 0186e32 Compare September 19, 2026 18:01
@HeyItsGilbert
HeyItsGilbert merged commit 5f271be into main Sep 19, 2026
6 of 7 checks passed
@HeyItsGilbert
HeyItsGilbert deleted the fix/koan-runspace-ps51-create branch September 19, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants