PowerShell: PowerShell 7.4.0-preview.4 fails to start on Windows PC when disconnected from domain network

Prerequisites

Steps to reproduce

  1. Installed pwsh 7.4.0-preview-4 on a domain joined PC, but the PC was on an external network provided by a mobile hotspot.
  2. Tried to launch pwsh-preview after installing

Expected behavior

PowerShell launches normally and prompt provided.

Actual behavior

PowerShell fails to start with the following message:

The shell cannot be started. A  failure occurred during initialization:
Object reference not set to an instance of an object.

Note that if the PC is on the domain network, the preview release starts normally. It does not start if either a different network connection is used that doesn’t have access to the domain network, or the network is turned off all together.

I also tested on pwsh 7.3.2 and pwsh 7.4.0-preview.3 and on both these versions pwsh will start in either state so the bug must have been introduced between 7.4.0-preview.3 and 7.4.0-preview.4.

I was not able to inspect the exception in the release version as the shell does not stay running. I built a debug version from my working area (that is between preview.3 and preview.4 in terms of code), and found it asserted on the machine in question with the following error:

pathToAdd should not be null according to contract of the function.

This is being triggered in GetModulePath of ModuleIntrinsics.cs when it tries to add a path to the module path, but the value it’s trying to add is null.

I tried checking if each of personalModulePathToUse, sharedModulePath and systemModulePathToUse is null before allowing them to be added, and with that change, the debug version of pwsh starts on the machine in question when in the disconnected state, but I’m not clear on what this code is doing with the path indices after adding them so I’m not confident to provide a PR for this.



### Error details

_No response_

### Environment data

```powershell
Name                           Value
----                           -----
PSVersion                      7.4.0-preview.4
PSEdition                      Core
GitCommitId                    7.4.0-preview.4
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Thanks @crlogic

It’s great that the change stops the crash, but it is code I am really unfamiliar with and there might be other things that break due to the unexpected return value from that API that I didn’t account for. It will need a careful review by MS team more familiar with what that code does and may need rework before it is accepted but it least we know the cause of the problem.