{"record":{"id":"8bcb3bdee72ff9db","repo":"stride3d/stride","slug":"a-packageviewmodel-cannot-contain-two-isntances-of","errorCode":null,"errorMessage":"A PackageViewModel cannot contain two isntances of DependencyCategoryViewModel","messagePattern":"A PackageViewModel cannot contain two isntances of DependencyCategoryViewModel","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/PackageViewModel.cs","lineNumber":791,"sourceCode":"\n            if (xAssets != null)\n            {\n                if (yAssets != null)\n                    return string.Compare(xAssets.Name, yAssets.Name, StringComparison.InvariantCultureIgnoreCase);\n                return -1;\n            }\n            if (xProject != null)\n            {\n                if (yProject != null)\n                {\n                    return xProject.CompareTo(yProject);\n                }\n                return yAssets != null ? 1 : -1;\n            }\n            if (xDependencies != null)\n            {\n                if (yDependencies != null)\n                    throw new InvalidOperationException(\"A PackageViewModel cannot contain two isntances of DependencyCategoryViewModel\");\n                return 1;\n            }\n            throw new InvalidOperationException(\"Unable to sort the given items for the Content collection of PackageViewModel\");\n        }\n    }\n    public abstract class PickablePackageViewModel : DispatcherViewModel\n    {\n        protected PickablePackageViewModel([NotNull] IViewModelServiceProvider serviceProvider)\n            : base(serviceProvider)\n        {\n        }\n\n        public abstract string Name { get; }\n\n        public abstract DependencyRange DependencyRange { get; }\n    }\n\n    public class LoadedPickablePackageViewModel : PickablePackageViewModel","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/PackageViewModel.cs#L773-L809","documentation":"PackageViewModel's Content collection comparer assumes at most one DependencyCategoryViewModel item. The sort comparison throws InvalidOperationException when two DependencyCategoryViewModel instances are compared, which would indicate a corrupted Content collection.","triggerScenarios":"Adding a second DependencyCategoryViewModel to PackageViewModel.Content, causing the sort comparer to encounter xDependencies and yDependencies both non-null.","commonSituations":"Custom plugins or re-initialization code inserting a duplicate dependencies category into the Content collection.","solutions":["Ensure only one DependencyCategoryViewModel is added to Content","Reuse the existing dependencies category instance","Deduplicate Content items before sorting"],"exampleFix":"// before\ncontent.Add(new DependencyCategoryViewModel(serviceProvider, package));\n// after\nif (!content.OfType<DependencyCategoryViewModel>().Any()) content.Add(new DependencyCategoryViewModel(serviceProvider, package));","handlingStrategy":"validation","validationCode":"if (content.OfType<DependencyCategoryViewModel>().Count() > 1) throw new InvalidOperationException(\"Duplicate DependencyCategoryViewModel in Content\");","typeGuard":"bool HasSingleDependencyCategory(System.Collections.IEnumerable c) => c.OfType<DependencyCategoryViewModel>().Take(2).Count() < 2;","tryCatchPattern":"try { SortContent(content); } catch (InvalidOperationException) { /* deduplicate and re-sort */ }","preventionTips":["Add only one DependencyCategoryViewModel","Reuse existing category instances","Deduplicate Content before sorting"],"tags":["viewmodel","invariant","sorting"],"backgroundTag":"internal-invariant-violation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}