PowerShell / PowerShell/PowerShellEditorServices
Script Content Triggers unhandled Newtonsoft.Json.JsonSerializationException
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 767
- 派生
- 266
- 平均合并
- 3 天 16 小时
- 30 天内合并 PR
- 1
描述
Prerequisites
- I have written a descriptive issue title.
- I have searched all open and closed issues to ensure it has not already been reported.
- I have read the troubleshooting guide.
- I am sure this issue is with PowerShell Editor Services itself and does not reproduce in a standalone PowerShell instance, and is not an issue with my editor.
- I have verified that I am using the latest version of PowerShell Editor Services.
- If this is a security issue, I have read the security issue reporting guidance.
Summary
When the following code snippet is encountered in a user created PowerShell script, and the script's path is in the environment path variable, PowerShellEditorServices fails. This appears to be caused by a Newtonsoft.Json.JsonSerializationException (For additional details, see the included PowerShellEditorServices-14896.log file included below).
Because the PowerShellEditorServices is used by the PowerShell Extension for Visual Studio Code, both the extension's Command Explorer and Intellisense stop working when this exception occurs. Ideally, I feel the PowerShellEditorServices should gracefully handle and report the exception and continue running.
param (
[Parameter(Mandatory=$false)]
[ValidateScript({
if ($_ -is [int] -and $_ -ge 0) {
$true
} else {
throw "The input argument be a positive integer or zero."
}
})]
[int]$DaysBack = 0 # Default value is 0
)
PowerShell Version
PS ~> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.3
PSEdition Core
GitCommitId 7.4.3
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Editor Version
Installed PowerShell Extension for Visual Studio Code.
PowerShell Editor Services Version
N/A
Steps to Reproduce
In Windows 11:
- Insert aforementioned code snippet into any user defined PowerShell script.
- Make sure the script can be found by the PowerShellEditorServices by including its fully qualified path (not file name) in the path environment variable.
- Open Visual Studio Code (with the PowerShell for VS Code extension (by Microsoft) installed.
- Click on the PowerShell icon in the left panel, to show the Command Explorer. (You may need to enable this extension's setting: PowerShell>SideBar: Command Explorer Visibility
- The Command Explorer will fail to enumerate and Intellisense will stop working for PowerShell scripts.
Visuals
No response
Logs
PowerShellEditorServices-14896.log
StartEditorServices-14896.log
vscode-powershell.log
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用提供的 PowerShell 代码片段重现故障,并检查 PowerShellEditorServices-14896.log、StartEditorServices-14896.log 和 vscode-powershell.log。追踪 PowerShell Editor Services 中未处理的序列化故障;当异常得到处理,且 Command Explorer 枚举和 IntelliSense 继续正常工作时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, powershell, vscode
- 领域
- developer-experience, devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100