stride3d/stride · error · InvalidOperationException

Could not find dependency

Error message

Could not find dependency {0} when processing bundle {1}

What it means

ObjectNode.Remove(item, itemIndex) requires a NodeIndex that actually resolves to a value; when itemIndex.TryGetValue returns false (an empty index) the method throws ArgumentException naming the itemIndex parameter. Removal from a collection node is always addressable by an index.

Solutions

  1. Pass the real NodeIndex of the item being removed (as obtained from enumeration or the selection).
  2. Validate with itemIndex.TryGetValue(out _) before calling Remove.
  3. If the item's index is unknown, look it up via the collection descriptor before removing.

Example fix

// before
node.Remove(item, NodeIndex.Empty);
// after
if (!itemIndex.TryGetValue(out _)) throw new InvalidOperationException("Remove requires a valid item index");
node.Remove(item, itemIndex);
Defensive patterns

Strategy: validation

Validate before calling

if (!itemIndex.TryGetValue(out _)) throw new InvalidOperationException("Remove requires a resolvable NodeIndex");
node.Remove(item, itemIndex);

Type guard

bool HasIndex(NodeIndex idx) => idx.TryGetValue(out _);

Try / catch

try { node.Remove(item, itemIndex); }
catch (ArgumentException ex) when (ex.ParamName == nameof(itemIndex)) { /* re-acquire the correct index for the item */ }

Prevention

When it happens

Trigger: Calling ObjectNode.Remove with NodeIndex.Empty or an otherwise unresolvable index, e.g. Remove(item, NodeIndex.Empty) or an index built without a valid index value.

Common situations: Copy-pasted Add-style code where an empty index is acceptable, reused for Remove; UI code that lost track of the selected item's index and passes a default NodeIndex.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/7d4760e02b4dd266. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.AssetCompiler/BundlePacker.cs:142

                        resolvedDefaultBundle.AssetUrls.Add(asset.Key);
                    }
                }

                // Pass4: Resolve dependencies
                foreach (var bundle in resolvedBundles)
                {
                    // Every bundle depends implicitely on default bundle
                    if (bundle.Key != "default")
                    {
                        bundle.Value.Dependencies.Add(resolvedBundles["default"]);
                    }

                    // Add other explicit dependencies
                    foreach (var dependencyName in bundle.Value.Source.Dependencies)
                    {
                        ResolvedBundle dependency;
                        if (!resolvedBundles.TryGetValue(dependencyName, out dependency))
                            throw new InvalidOperationException(string.Format("Could not find dependency {0} when processing bundle {1}", dependencyName, bundle.Value.Name));

                        bundle.Value.Dependencies.Add(dependency);
                    }
                }

                logger.Info("Generate bundles: Assign assets to bundles...");

                // Pass5: Topological sort (a.k.a. build order)
                // If there is a cyclic dependency, an exception will be thrown.
                var sortedBundles = TopologicalSort(resolvedBundles.Values, assetBundle => assetBundle.Dependencies);

                // Pass6: Find which ObjectId belongs to which bundle
                foreach (var bundle in sortedBundles)
                {
                    // Add objects created by dependencies
                    foreach (var dep in bundle.Dependencies)
                    {
                        // ObjectIds

View on GitHub (pinned to 96fad776d2)