Repository navigation
[1.2.0-preview1] TryConvertFromJson: Cannot parse PSResourceInfo from json object with error #1840
Copy link
Copy link
Closed
Labels
Description
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.
PSResourceGet/src/code/PSResourceInfo.cs
Lines 728 to 730 in 06aec34
| JsonElement dependencyGroup in dependencyGroupsElement.EnumerateArray().Where( | |
| x => !string.IsNullOrWhiteSpace(x.GetProperty("@id").GetString()) | |
| ) |
PSResourceGet/src/code/PSResourceInfo.cs
Lines 737 to 740 in 06aec34
| 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 dictionaryError 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
1Environment 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.0Visuals
No response
Reactions are currently unavailable
Activity
o-l-a-v commentedon Jul 4, 2025
Interesting,
pwsh.galleryandpreview.pwsh.gallerygives different results.pwsh.gallery: https://pwsh.gallery/registration/az/index.jsonpreview.pwsh.gallery: https://preview.pwsh.gallery/az/page/recent.jsonSeems to me that
pwsh.galleryuses Sleet, but notpreview.pwsh.gallery? Thats what the index tells us at least.pwsh.gallery: https://pwsh.gallery/index.jsonpreview.pwsh.gallery: https://preview.pwsh.gallery/index.jsonI tested
Find-PSResource -Repository 'pwsh.gallery' -Name 'Az', it worked. ButFind-PSResource -Repository 'preview.pwsh.gallery' -Name 'Az'did not.We should probably conform to the spec, not checking for something that is not mandatory. Even though Sleet outputs
@idtoo.I believe changing from getting
@idtoidshould fix it.fflaten commentedon Jul 4, 2025
You're right. I mixed up preview and prod pwsh.gallery at one point. 🤦♂️
Preview is probably not Sleet.
NuGet v3 dependencies - Fix #1840 (#1841)