Skip to content

Run PowerShell class static methods in the correct Runspace/SessionState - #4209

Merged
Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
daxian-dbw:class
Jul 15, 2017
Merged

Run PowerShell class static methods in the correct Runspace/SessionState#4209
Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
daxian-dbw:class

Conversation

@daxian-dbw

Copy link
Copy Markdown
Member

Fix #4001

Summary

When the same script file gets executed in multiple Runspaces, the RuntimeType generated from the powershell class defined in the file will be shared among those Runspaces. For different Runspaces, different SessionState should be used to run the static methods.

Fix

We use the SessionStateKeeper to query for the correct SessionState to use for a static method call.
We already use SessionStateKeeper to track the Runspace/SessionState where a PowerShell class is defined, and thus we can leverage this for the static method invocation.

Comment thread src/System.Management.Automation/engine/runtime/Operations/ClassOps.cs Outdated
Comment thread src/System.Management.Automation/engine/runtime/Operations/ClassOps.cs Outdated
Comment thread src/System.Management.Automation/engine/runtime/Operations/ClassOps.cs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit c5f3a19 into PowerShell:master Jul 15, 2017
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
…ate (PowerShell#4209)

Summary
----------
When the same script file gets executed in multiple Runspaces, the RuntimeType generated from the powershell class defined in the file will be shared among those Runspaces. For different Runspaces, different SessionState should be used to run the static methods.

Fix
---
We use the `SessionStateKeeper` to query for the correct `SessionState` to use for a static method call.
We already use `SessionStateKeeper` to track the `Runspace/SessionState` where a PowerShell class is defined, and thus we can leverage this for the static method invocation.
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.

4 participants