PowerShell / PowerShell/PowerShell
Error starting PowerShell 7.4.0+
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
- Install PowerShell 7.4.0
- Start it
- Create a
powershell.config.jsonand setPSModulePathto multiple paths, separated by;(path separator char) (see reference). - See it fail
Expected behavior
It starts, like 7.3 did.
Actual behavior
It fails with:
PowerShell 7.4.0
The shell cannot be started. A failure occurred during initialization:
Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'startIndex')
Error details
Not possible.
Environment data
Not possible, but it is version 7.4.0.
Visuals
This is starting from Nushell:
This is starting it from Windows Terminal:
Additional context
Downloaded and installed this file: https://github.com/PowerShell/PowerShell/releases/download/v7.4.0/PowerShell-7.4.0-win-x64.msi
I debugged and found out that the exception is ocurring at this location (ModuleIntrinsics.UpdatePath):
https://github.com/PowerShell/PowerShell/blob/ad2bf787e4e7dfde9123a67349cf1ae6ccdfc984/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs#L1278
The arguments for UpdatePath are:
path: a string with a ; separated list of paths
pathToAdd: another string with a ; separated list of paths
insertIndex: 0
The call that is failing is the one to path.IndexOf, which is passed ; and -1 (which is the result from the call to PathContainsSubstring).
The problem only happens because pathToAdd has several paths with the ; separator. If it was a single path without ; it would work.
The issue seems to have been introduced in commit 3710671c16de9bcbd945389a22a88b994cd02bcd.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs at ModuleIntrinsics.UpdatePath, focusing on the path.IndexOf call described in the issue. Reproduce the failure with a powershell.config.json whose PSModulePath contains multiple semicolon-separated paths, then verify that PowerShell 7.4 starts successfully with that configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100