Skip to content
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

Error starting PowerShell 7.4.0+ #20706

Open
5 tasks done
giggio opened this issue Nov 16, 2023 · 12 comments
Open
5 tasks done

Error starting PowerShell 7.4.0+ #20706

giggio opened this issue Nov 16, 2023 · 12 comments
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@giggio
Copy link

giggio commented Nov 16, 2023

Prerequisites

Steps to reproduce

  1. Install PowerShell 7.4.0
  2. Start it
  3. Create a powershell.config.json and set PSModulePath to multiple paths, separated by ; (path separator char) (see reference).
  4. 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:

from nu

This is starting it from Windows Terminal:

from wt

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):

insertIndex = path.IndexOf(Path.PathSeparator, PathContainsSubstring(path, pathToAdd));

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 3710671.

@giggio giggio added the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 16, 2023
@rhubarb-geek-nz
Copy link

rhubarb-geek-nz commented Nov 16, 2023

Can you check with "Add or Remove programs" settings that there is only one PowerShell MSI installed, and you don't have both 7.3.9 and 7.4.0?

The reason I say that is I found I had both installed, one with a normal MSI icon, the other with a PowerShell icon.

@giggio
Copy link
Author

giggio commented Nov 16, 2023

@rhubarb-geek-nz I did, I hadn't.

@B-Art
Copy link

B-Art commented Nov 18, 2023

There are at least 4 ways to install Pwsh on Windows:
From MSStore, via MSI, via Winget and Unzipping the download.
Which one did you use @giggio ?
https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4

@giggio
Copy link
Author

giggio commented Nov 18, 2023

First I tried via winget. Then via the MSI download. Same result.

@rhubarb-geek-nz
Copy link

rhubarb-geek-nz commented Nov 22, 2023

First I tried via winget. Then via the MSI download. Same result.

Have you tried completely uninstalling the previous MSI first? Not ideal I know, in-place updates should work. Use "Add or Remove programs" to see what is installed, and also check the directory "c:\Program Files\PowerShell\7"

@giggio
Copy link
Author

giggio commented Nov 22, 2023

Have you tried completely uninstalling the previous MSI first? Not ideal I know, in-place updates should work. Use "Add or Remove programs" to see what is installed, and also check the directory "c:\Program Files\PowerShell\7"

I have.

I have now also tried installing the Microsoft Store Version, and I get the same error:
image

@giggio
Copy link
Author

giggio commented Nov 22, 2023

Tried now using the global tool, it also does not work:

image

I installed 7.3.10, as it still works. :(

@rhubarb-geek-nz
Copy link

rhubarb-geek-nz commented Nov 22, 2023

Alas, there are enough other problems with 7.4.0 to suggest sticking with 7.3.10 ( for the moment ).

@giggio
Copy link
Author

giggio commented Jan 25, 2024

The problem persists at version 7.4.1, released more recently.

image

@giggio
Copy link
Author

giggio commented Jan 25, 2024

Also, tried using version 7.5 preview from the store, also broken.

image

@giggio
Copy link
Author

giggio commented Mar 13, 2024

I have tracked the error and added the explanation of why it is happening to the additional context section of the issue.

@giggio giggio changed the title Error starting PowerShell 7.4.0 Error starting PowerShell 7.4.0+ Mar 13, 2024
giggio added a commit to giggio/PowerShell that referenced this issue Mar 13, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR Indicates that a PR is out for the issue label Mar 13, 2024
@Alvaka-KThor
Copy link

I am also experiencing this issue. I've had to use PSModulePath environment variable within System Properties in the meantime, which is not a perfect workaround.

giggio added a commit to giggio/poshfiles that referenced this issue Apr 29, 2024
There is a bug in PowerShell that is making it fail.
See: PowerShell/PowerShell#20706
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants