stride3d/stride · error · InvalidOperationException
Unable to sort the given items for the Content collection…
Error message
Unable to sort the given items for the Content collection of PackageViewModel
What it means
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.
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
Example fix
// before content.Add(myCustomNode); // after // keep custom nodes in a separate collection, or extend the comparer to handle myCustomNode
Defensive patterns
Strategy: validation
Validate before calling
if (content.Any(i => !(i is AssetViewModel || i is DirectoryViewModel || i is DependencyCategoryViewModel))) throw new InvalidOperationException("Unsupported item in PackageViewModel.Content"); Type guard
bool IsSortableContentItem(object i) => i is AssetViewModel || i is DirectoryViewModel || i is DependencyCategoryViewModel;
Try / catch
try { SortContent(content); } catch (InvalidOperationException) { /* remove unsupported items */ } Prevention
- Only add asset/directory/dependency-category nodes to Content
- Extend the comparer for new node types
- Keep custom nodes in separate collections
When it happens
Trigger: Inserting an item into PackageViewModel.Content that is not an asset, directory, or the single dependency category, then triggering a sort of the collection.
Common situations: Plugins adding custom view model nodes to the Content collection without extending the comparer.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- A PackageViewModel cannot contain two isntances of…
- Cannot support dimension
- Type [ ] is not supported as a modifiable collection
- Unable to find a serializer for the type
- Unable to serialize scalar
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/92be3b7746ef982c.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/ViewModel/PackageViewModel.cs:794
if (yAssets != null)
return string.Compare(xAssets.Name, yAssets.Name, StringComparison.InvariantCultureIgnoreCase);
return -1;
}
if (xProject != null)
{
if (yProject != null)
{
return xProject.CompareTo(yProject);
}
return yAssets != null ? 1 : -1;
}
if (xDependencies != null)
{
if (yDependencies != null)
throw new InvalidOperationException("A PackageViewModel cannot contain two isntances of DependencyCategoryViewModel");
return 1;
}
throw new InvalidOperationException("Unable to sort the given items for the Content collection of PackageViewModel");
}
}
public abstract class PickablePackageViewModel : DispatcherViewModel
{
protected PickablePackageViewModel([NotNull] IViewModelServiceProvider serviceProvider)
: base(serviceProvider)
{
}
public abstract string Name { get; }
public abstract DependencyRange DependencyRange { get; }
}
public class LoadedPickablePackageViewModel : PickablePackageViewModel
{
public LoadedPickablePackageViewModel(PackageViewModel package) : base(package.ServiceProvider)
{View on GitHub (pinned to 96fad776d2)