Type
bug
Title:
UniversalFeedClient.ListPackagesAsync throws InvalidOperationException when working with local Repository
Created:
6/20/2023 9:48:43 AM by EMAG-fotto
Status:
closed on 6/24/2023 11:27:20 PM
Last pulled:
6/24/2023 11:28:22 PM
Description:
Following codesnipped throws an exception when calling await feed.ListPackagesAsync(null, null): ``` using Inedo.UPack.Net; var ep = new UniversalFeedEndpoint("file:///c:/upack/"); //var ep = new UniversalFeedEndpoint("https://packages.edna.emag.com/upack/EMAG-Installer/"); var feed = new UniversalFeedClient(ep); var packages = await feed.ListPackagesAsync(null, null); foreach (var package in packages) { Console.WriteLine(package.Name); } ``` The Stacktrace: ``` [Ausnahme] System.Text.Json.dll!System.Text.Json.ThrowHelper.ThrowInvalidOperationException_NodeAlreadyHasParent() [Ausnahme] System.Text.Json.dll!System.Text.Json.Nodes.JsonNode.AssignParent(System.Text.Json.Nodes.JsonNode parent) [Ausnahme] System.Text.Json.dll!System.Text.Json.Nodes.JsonObject.SetItem.AnonymousMethod__0() [Ausnahme] System.Text.Json.dll!System.Text.Json.JsonPropertyDictionary.SetValue(string propertyName, T value, System.Action assignParent) [Ausnahme] System.Text.Json.dll!System.Text.Json.Nodes.JsonObject.SetItem(string propertyName, System.Text.Json.Nodes.JsonNode value) [Ausnahme] Inedo.UPack.dll!Inedo.UPack.Net.LocalPackageRepository.GetMungedPackage(System.Collections.Generic.IEnumerable packageVersions) [Ausnahme] Inedo.UPack.dll!Inedo.UPack.Net.LocalPackageRepository.ListPackages.AnonymousMethod__5_1(System.Linq.IGrouping g) [Ausnahme] System.Linq.dll!System.Linq.Enumerable.WhereSelectEnumerableIterator.ToList() [Ausnahme] System.Linq.dll!System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable source) [Ausnahme] Inedo.UPack.dll!Inedo.UPack.Net.UniversalFeedClient.ListPackagesAsync(string group, int? maxCount, System.Threading.CancellationToken cancellationToken) [Ausnahme] UPack.dll!Program.
$(string[] args) Zeile 6 unter C:\_Projekte\Versuche\UPack\UPack\Program.cs (6) System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task task) System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task) System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.GetResult() [Warten auf asynchronen Vorgang, Doppelklick oder EINGABE zur Anzeige asynchroner Aufruflisten] UPack.dll!Program.
(string[] args) ``` I think I located the problem in the method GetMungedPackage in class LocalPackageRepository. There JsonObjects are "copied"without removing their parent first, which causes the exception. Possible solution would be: ``` private static JsonObject GetMungedPackage(IEnumerable packageVersions) { const string VERSION = "version"; const string LATEST_VERSION = "latestVersion"; const string VERSIONS = "versions"; var sorted = (from p in packageVersions let v = UniversalPackageVersion.Parse((string?)p.JObject[VERSION]) orderby v descending select p).ToList(); var latest = (JsonObject)JsonNode.Parse(sorted.First().JObject.ToJsonString())!; var latestVersion = latest[VERSION]; latest.Remove(VERSION); latest[LATEST_VERSION] = latestVersion; var copyDeleteAndReturnVersionFrom = (PackageFile f) => { var v = f.JObject[VERSION]; f.JObject.Remove(VERSION); return v; }; latest[VERSIONS] = new JsonArray(sorted.Select(v => copyDeleteAndReturnVersionFrom(v)).ToArray()); return latest; } ```