{"record":{"id":"92be3b7746ef982c","repo":"stride3d/stride","slug":"unable-to-sort-the-given-items-for-the-content-collection-of","errorCode":null,"errorMessage":"Unable to sort the given items for the Content collection of PackageViewModel","messagePattern":"Unable to sort the given items for the Content collection of PackageViewModel","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/PackageViewModel.cs","lineNumber":794,"sourceCode":"                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\n    {\n        public LoadedPickablePackageViewModel(PackageViewModel package) : base(package.ServiceProvider)\n        {","sourceCodeStart":776,"sourceCodeEnd":812,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/PackageViewModel.cs#L776-L812","documentation":"PackageViewModel's Content collection sorter ends with a fallback InvalidOperationException when it cannot classify the compared items: neither an AssetViewModel, a DirectoryViewModel, nor a DependencyCategoryViewModel pattern matched. This guards against unknown item types sneaking into Content.","triggerScenarios":"Inserting an item into PackageViewModel.Content that is not an asset, directory, or the single dependency category, then triggering a sort of the collection.","commonSituations":"Plugins adding custom view model nodes to the Content collection without extending the comparer.","solutions":["Only add supported item types (asset, directory, dependency category) to Content","Extend the sort comparer if a new node type is legitimately needed","Remove unsupported items from Content before sorting"],"exampleFix":"// before\ncontent.Add(myCustomNode);\n// after\n// keep custom nodes in a separate collection, or extend the comparer to handle myCustomNode","handlingStrategy":"validation","validationCode":"if (content.Any(i => !(i is AssetViewModel || i is DirectoryViewModel || i is DependencyCategoryViewModel))) throw new InvalidOperationException(\"Unsupported item in PackageViewModel.Content\");","typeGuard":"bool IsSortableContentItem(object i) => i is AssetViewModel || i is DirectoryViewModel || i is DependencyCategoryViewModel;","tryCatchPattern":"try { SortContent(content); } catch (InvalidOperationException) { /* remove unsupported items */ }","preventionTips":["Only add asset/directory/dependency-category nodes to Content","Extend the comparer for new node types","Keep custom nodes in separate collections"],"tags":["viewmodel","sorting","unsupported-type"],"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"}