stride3d/stride · error · InvalidOperationException
A PackageViewModel cannot contain two isntances of…
Error message
A PackageViewModel cannot contain two isntances of DependencyCategoryViewModel
What it means
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.
Solutions
- Ensure only one DependencyCategoryViewModel is added to Content
- Reuse the existing dependencies category instance
- Deduplicate Content items before sorting
Example fix
// before content.Add(new DependencyCategoryViewModel(serviceProvider, package)); // after if (!content.OfType<DependencyCategoryViewModel>().Any()) content.Add(new DependencyCategoryViewModel(serviceProvider, package));
Defensive patterns
Strategy: validation
Validate before calling
if (content.OfType<DependencyCategoryViewModel>().Count() > 1) throw new InvalidOperationException("Duplicate DependencyCategoryViewModel in Content"); Type guard
bool HasSingleDependencyCategory(System.Collections.IEnumerable c) => c.OfType<DependencyCategoryViewModel>().Take(2).Count() < 2;
Try / catch
try { SortContent(content); } catch (InvalidOperationException) { /* deduplicate and re-sort */ } Prevention
- Add only one DependencyCategoryViewModel
- Reuse existing category instances
- Deduplicate Content before sorting
When it happens
Trigger: Adding a second DependencyCategoryViewModel to PackageViewModel.Content, causing the sort comparer to encounter xDependencies and yDependencies both non-null.
Common situations: Custom plugins or re-initialization code inserting a duplicate dependencies category into the Content collection.
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
- Unable to sort the given items for the Content collection…
- A transaction failed to be created.
- IsObjectReference returned true for an object that is not…
- Asset of type was migrated, but still its new version…
- Package RootDirectory is null
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/8bcb3bdee72ff9db.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/ViewModel/PackageViewModel.cs:791
if (xAssets != null)
{
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 : PickablePackageViewModelView on GitHub (pinned to 96fad776d2)