question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stevenebutlercommented, Jul 11, 2023

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.

0reactions
crlogiccommented, Jul 11, 2023

Jenkins tested successfully!

$psversiontable
'I found this string: [{0}]' -f [Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments) 

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installing PowerShell on Windows
When you set up PowerShell Remoting you get an error message and are disconnected from the device. PowerShell has to restart WinRM. Now...
Read more >
Troubleshoot errors that occur when you join Windows ...
This article describes several common error messages that can occur when you join client computers that are running Windows to a domain.
Read more >
about Remote Troubleshooting - PowerShell
To start Windows PowerShell with the Run as administrator option, right-click on the PowerShell icon in the Start Menu and select Run as ......
Read more >
Can't leave a domain on Windows 11
If your computer has network drives mapped to resources on the domain, disconnect them before attempting to leave the domain. Network drive ...
Read more >
Incorrect results when you run AD Windows PowerShell ...
This issue occurs when you use Active Directory Module for Windows PowerShell on a Windows Server 2008 R2-based domain controller.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found