Skip to content

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

Open
HeyItsGilbert wants to merge 1 commit into
build/reusable-ci-workflowfrom
fix/koan-runspace-ps51-create
Open

HeyItsGilbert wants to merge 1 commit into
build/reusable-ci-workflowfrom
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
[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 eb21735 to 05ec4f6 Compare September 18, 2026 23:30
@github-actions

Copy link
Copy Markdown

Test Results

    4 files  ±0    104 suites  ±0   1m 54s ⏱️ +16s
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 05ec4f6. ± Comparison against base commit 5aa5f22.

@HeyItsGilbert
HeyItsGilbert added this pull request to stack #502 September 18, 2026 23:42
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