vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Debugging Remote Runspace: the editor could not be opened due to an unexpected error: cannot read properties of null (reading 'create')

Open Rom265 opened this issue 10 months ago • 10 comments

Prerequisites

  • [x] I have written a descriptive issue title.
  • [x] I have searched all open and closed issues to ensure it has not already been reported.
  • [x] I have read the troubleshooting guide.
  • [x] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • [x] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • [x] If this is a security issue, I have read the security issue reporting guidance.

Summary

I try to run a script with

wait-debugger; & MyCommand

(where & MyCommand stands in for some command), a tab opens in VS Code with a red circle with an X. It says, "the editor could not be opened due to an unexpected error: cannot read properties of null (reading 'create')" with a "Try Again" button. I have seen this a few times recently. If I close and reopen VS Code (a frequent fix for when it bugs out), it still keeps doing that. It looks like an error from VS Code, but it happens when I'm trying to run the debugger with Powershell; so, it probably makes most sense to post this here first.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.7
PSEdition                      Core
GitCommitId                    7.4.7
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2025.0.0
InstanceId       : c84edc60-e725-42a9-954c-cb01d1fea8ba
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.96.4
cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba
x64

Extension Version

[email protected]

Steps to Reproduce

write command. Hit enter. The call stack shows paused on step: <Breakpoint> <ScriptBlock>

Visuals

Image

Logs

No response

Rom265 avatar Feb 01 '25 22:02 Rom265

We don't have great debug state syncing between the extension terminal and LSP just yet (it's a work in progress PR). Without more info to debug, I can only suggest using the VS Code debugger UI to set breakpoints and debug whatever you're trying to.

andyleejordan avatar Feb 04 '25 01:02 andyleejordan

This issue has been labeled as resolved, please verify the provided fix (or other reason).

github-actions[bot] avatar Feb 04 '25 01:02 github-actions[bot]

We don't have great debug state syncing between the extension terminal and LSP just yet (it's a work in progress PR). Without more info to debug, I can only suggest using the VS Code debugger UI to set breakpoints and debug whatever you're trying to.

I reverted to the previous version of the Powershell extension and it has not happened since.

Rom265 avatar Feb 04 '25 21:02 Rom265

This issue has been labeled as resolved, please verify the provided fix (or other reason).

github-actions[bot] avatar Feb 04 '25 22:02 github-actions[bot]

We don't have great debug state syncing between the extension terminal and LSP just yet (it's a work in progress PR). Without more info to debug, I can only suggest using the VS Code debugger UI to set breakpoints and debug whatever you're trying to.

I can confirm, that i face the issue with the VSCode debugger and breakpoints as well. If you want to Step-Into a function, vscode falls into the described issue in that post.

I also can confirm the resolution of @Rom265 : Switch back from Version 2025.0.0 to 2024.4.0

LKo-exp4 avatar Feb 10 '25 12:02 LKo-exp4

This issue has been labeled as resolved, please verify the provided fix (or other reason).

github-actions[bot] avatar Feb 10 '25 13:02 github-actions[bot]

@LKo-exp4 is it specific to wait debugger or are you using a launch configuration? Can you record a reproduction? In Windows 11 you can hit win-shift-R to get native recording and it's pasteable directly into github.

JustinGrote avatar Feb 10 '25 20:02 JustinGrote

I confirmed that I have no issue using Step-Into etc. with v2025.0.0 and PowerShell 7.4. I also tried Wait-Debugger; & Get-ChildItem (and a command that came from a sourced script) with no problems. We need further repro steps / logs to look into this. Thanks!

andyleejordan avatar Feb 11 '25 19:02 andyleejordan

@JustinGrote Sorry for the delayed response.

I can reproduce the issue. I am debugging a powershell script using AzureFunctions local development environment. Therefore I am using a launch configuration to attach to the azure functions process.

My launch configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to PowerShell Functions",
            "type": "PowerShell",
            "request": "attach",
            "customPipeName": "AzureFunctionsPSWorker",
            "runspaceId": 1,
            "preLaunchTask": "func: host start"
        }
    ]
}

I set a Breakpoint into my code, start the debugger by hitting F5. If the Breakpoint is hit, i try to Step-into the Function "Get-TestFunction" and receive the error like seen in the video. The TestFunction is part of a module that is imported by the AzFunction worker as part of the startup.

https://github.com/user-attachments/assets/69ca8837-f538-4554-89d6-5292e596d668

I am using P.S 7.4 and VSCode Version 1.96.4 and PSExtension Version 2025.0.0. Azure Functions Version 2.0 with Azure Functions extension bundle for ServiceBus integration

  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  },

LKo-exp4 avatar Feb 21 '25 09:02 LKo-exp4

Thanks! Debugging remote runspaces can be inherently finicky because we have to do some ugly stuff to fetch the call stack and whatnot and it's hard to have good test coverage in that area. I'll try to take a look but I can't commit to a fix.

JustinGrote avatar Feb 21 '25 13:02 JustinGrote