Skip to content

Fix Export-ModuleMember bug for scriptblocks having no context - #8363

Merged
Travis Plunk (TravisEz13) merged 3 commits into
PowerShell:masterfrom
PaulHigin:fix_exportmodulemember_nocontext
Nov 30, 2018
Merged

Travis Plunk (TravisEz13) merged 3 commits into
PowerShell:masterfrom
PaulHigin:fix_exportmodulemember_nocontext

Conversation

@PaulHigin

Copy link
Copy Markdown
Contributor

PR Summary

Export-ModuleMember cmdlet throws an exception if module functions are exported across language boundaries (Windows only). But a scriptblock LanguageMode property can be null if the scriptblock is created without a PowerShell context, and this can happen through the PowerShell API called from C#. In this case Export-ModuleMember throws erroneously when no language mode restrictions are in play.

Fix is to check if LanguageMode is null before comparing context and scriptblock language modes.

PR Checklist

@TravisEz13
Travis Plunk (TravisEz13) merged commit 743a964 into PowerShell:master Nov 30, 2018
@PaulHigin
Paul Higinbotham (PaulHigin) deleted the fix_exportmodulemember_nocontext branch November 30, 2018 20:42
@kilasuit Ryan Yates (kilasuit) added WG-Cmdlets general cmdlet issues and removed WG-Cmdlets-Core labels Jul 17, 2026
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…Shell#8363)

Export-ModuleMember cmdlet throws an exception if module functions are exported across language boundaries (Windows only).  But a scriptblock LanguageMode property can be null if the scriptblock is created without a PowerShell context, and this can happen through the PowerShell API called from C#.  In this case Export-ModuleMember throws erroneously when no language mode restrictions are in play.

Fix is to check if LanguageMode is null before comparing context and scriptblock language modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Issue-Bug Issue has been identified as a bug in the product OS-Windows WG-Cmdlets general cmdlet issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants