New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report error when PowerShell built-in modules are missing #16628
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I do not understand why even try to look for built-in modules if they are hardwired to a particular version of SMA and the paths to them must be hardcoded. |
Turning the PR to a draft for now, as I'm working on a different solution without assuming the built-in modules have to be under |
…so use 'RemoteDesktop' instead
change of design was made, so need a new review
@iSazonov The design was changed to not assume the built-in modules are always under |
@anmenaga @SteveL-MSFT, please review when you have time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/CompatiblePSEditions.Module.Tests.ps1
Outdated
Show resolved
Hide resolved
What about Appx module? :-) |
@iSazonov Not sure what you mean. Appx module is not in the picture of the problem I tried to resolve here. |
I think we need add the module to stop list and load in wincompat mode.. |
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
@anmenaga I think this PR is ready. Can you please take a look? Thanks! |
Jumping in to make you aware that this PR would also fix #13157 🙂 |
Thanks @Fs00, I've updated the PR description with that info. |
As final notices:
|
Switch issue/PR fragments to use the timeline API in order to get that event.
🎉 Handy links: |
PR Summary
When a PowerShell built-in module is getting imported in the
WinCompat
mode, we check whether a core-edition compatible version of this module is available in module paths. If not, report error instead of blindly loading the module underSystem32
module path, because that could result in very confusing errors later on.Fix #13157. Related to #16525.
We also had a stack overflow issue reported from internal team when they were testing with PowerShell 7.2. The investigation showed the root cause was that they didn't recursively copy the
$PSHOME\Modules
when deploying their test infrastructure, and the stack overflow exception was caused by auto-loading attempts to loadMicrosoft.PowerShell.Utility
from theSystem32
module path.With this change, we should be able to avoid the confusing errors when somehow a user has the built-in modules missing. The error will explicitly call out that a core-edition compatible version of the built-in module cannot be found.
Here is an example to show the UX:
Basically, for built-in modules, PowerShell blocks the loading of the same module in
System32\WindowsPowerShell\v1.0\Modules
viaWinCompat
when a core-edition compatible version of such module cannot be found. When the core-edition compatible built-in modules are available, loading of the same module inSystem32
module path will proceed normally.Where is the check done?
The check is done in
PrepareNoClobberWinCompatModuleImport
.When importing a module remotely via
WinCompat
, if the module is a built-in module, or it's listed inWindowsPowerShellCompatibilityNoClobberModuleList
inpowershell.config.json
, we first attempt to load a core-edition compatible version of such module, and then proceed with loading the module remotely. This is howWInCompat
works today.This PR made an improvement to the existing code:
System32
module path when attempting to load a core-compatible version of the module, so thatSystem32
module path in$env:PSModulePath
.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.