Skip to content

[1.2.0-preview1] TryConvertFromJson: Cannot parse PSResourceInfo from json object with error #1840

Closed

Description

@fflaten

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

Find/Save/Install-PSResourceGet fails with some Nuget v3 repositories, ex. https://preview.pwsh.gallery, using latest preview.

This is likely caused by the mandatory checks for @id in dependencyGroup and dependencies introduced in #1778.

JsonElement dependencyGroup in dependencyGroupsElement.EnumerateArray().Where(
x => !string.IsNullOrWhiteSpace(x.GetProperty("@id").GetString())
)

foreach (
JsonElement dependency in dependenciesElement.EnumerateArray().Where(
x => !string.IsNullOrWhiteSpace(x.GetProperty("@id").GetString())
)

@id is not listed as required in docs for dependencyGroup and dependencies, so we should probably not rely on them.

/cc Olav Rønnestad Birkeland (@o-l-a-v)

Expected behavior

Find-PSResource, Save-PSResource, Install-PSResource should work with all Nuget v3 repositories

Actual behavior

PS > Register-PSResourceRepository -Name pwshgallery -Uri "https://preview.pwsh.gallery/index.json" -ApiVersion V3
PS > Find-PSResource -Repository pwshgallery -Name az

Find-PSResource: TryConvertFromJson: Cannot parse PSResourceInfo from json object with error: The given key was not present in the dictionary

Error details

Exception             :
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ConvertToPSResourceException
    Message : TryConvertFromJson: Cannot parse PSResourceInfo from json object with error: The given key was not present in the dictionary.
    HResult : -2146233088
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.FindHelper
CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel….Cmdlets.FindHelper:FindHelper) [Find-PSResource], ConvertToPSResourceException
FullyQualifiedErrorId : FindNameConvertToPSResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
InvocationInfo        :
    MyCommand        : Find-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 16
    Line             : Find-PSResource -Repository pwshgallery -Name az
    Statement        : Find-PSResource -Repository pwshgallery -Name az
    PositionMessage  : At line:1 char:1
                       + Find-PSResource -Repository pwshgallery -Name az
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Find-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.2.0      preview1   Microsoft.PowerShell.PSResourceGet  {Compress-PSResource, Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository…}

Name                           Value
----                           -----
PSVersion                      7.5.1
PSEdition                      Core
GitCommitId                    7.5.1
OS                             Microsoft Windows 10.0.26100
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

Activity

  1. o-l-a-v commented on Jul 4, 2025

    @o-l-a-v
    Contributor

    Interesting, pwsh.gallery and preview.pwsh.gallery gives different results.

    Image

    Seems to me that pwsh.gallery uses Sleet, but not preview.pwsh.gallery? Thats what the index tells us at least.

    I tested Find-PSResource -Repository 'pwsh.gallery' -Name 'Az', it worked. But Find-PSResource -Repository 'preview.pwsh.gallery' -Name 'Az' did not.

    • So it works with Sleet?

    We should probably conform to the spec, not checking for something that is not mandatory. Even though Sleet outputs @id too.

    I believe changing from getting @id to id should fix it.

  2. fflaten commented on Jul 4, 2025

    @fflaten
    Author

    You're right. I mixed up preview and prod pwsh.gallery at one point. 🤦‍♂️

    Preview is probably not Sleet.

  3. added a commit that references this issue on Jul 15, 2025
    5c54a8e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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