Skip to content

Powershell script with Generic method call cannot be edited in VS Code #4842

Closed
@hshenMcc

Description

@hshenMcc

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 the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

call [System.Text.Json.JsonSerializer]::Serialize in a powershell script. The script runs ok in VS code. But after editing anything in the script, the script failed at the call of [System.Text.Json.JsonSerializer]::Serialize. No issue if run the modified script in pwsh directly.

PowerShell Version

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

Visual Studio Code Version

1.84.2
1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
x64

Extension Version

ms-vscode.powershell@2023.8.0

Steps to Reproduce

testJson.zip
testJson.ps1 in the zip can run no problem in VS Code with output

this1:
{"FirstName":"John","LastName":"Doe"}

But if remove 1 in "this1", and run the script again in VS code, got output as
Line |
24 | $jsonString = [System.Text.Json.JsonSerializer]::Serialize[Person]($p …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Could not find a suitable generic method overload for "Serialize" with "1" type parameters, and the argument count: "1".
this:

No issue to run the modified script in pwsh. Something is wrong in Powershell extension.

Visuals

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions