stride3d/stride · error · ArgumentException

The given directory is not contained in the given package.

Error message

The given directory is not contained in the given package.

What it means

MoveAsset validates that the target directory view model actually belongs to the target package via DirectoryBaseViewModel.Match(newPackage). If the directory's package does not match the package argument, the combination is inconsistent and an ArgumentException is thrown before any transaction starts.

Solutions

  1. Pass a directory view model obtained from the same target package: newDirectory.Package.Match(newPackage) must be true.
  2. Resolve the directory through the target package's view model rather than reusing one from another package.
  3. Add a pre-check before the call and surface a clearer user-facing message on mismatch.

Example fix

// before
asset.MoveAsset(otherPackage, directoryFromSourcePackage);
// after
var targetDir = otherPackage.Directories.First(d => d.Path == "/target/path");
asset.MoveAsset(otherPackage, targetDir);
Defensive patterns

Strategy: validation

Validate before calling

if (!newDirectory.Package.Match(newPackage)) throw new ArgumentException("Target directory does not belong to the target package");
asset.MoveAsset(newPackage, newDirectory);

Type guard

bool IsValidMoveTarget(Package p, DirectoryBaseViewModel d) => d != null && d.Package.Match(p);

Try / catch

try { asset.MoveAsset(newPackage, newDirectory); }
catch (ArgumentException ex) { logger.Error(ex, "Directory/package mismatch in move target"); }

Prevention

When it happens

Trigger: Calling assetViewModel.MoveAsset(newPackage, newDirectory) where newDirectory is a directory from a different package than newPackage (e.g. moving an asset to a directory view model taken from another project).

Common situations: Multi-project workspaces where the source and target projects both have directory trees and the wrong tree node is grabbed; UI drag-drop handlers mixing view models across sessions.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs:324

                UndoRedoService.SetName(transaction, $"Reconcile {Url} with its archetypes");
            }
        }

        /// <inheritdoc/>
        public override string ToString()
        {
            return $"{{{GetType().Name}: {Url}}}";
        }

        /// <summary>
        /// Moves this asset in a different directory of a different project.
        /// </summary>
        /// <param name="newPackage">The target project.</param>
        /// <param name="newDirectory">The view model of the target directory.</param>
        /// <returns></returns>
        public bool MoveAsset(Package newPackage, [NotNull] DirectoryBaseViewModel newDirectory)
        {
            if (!newDirectory.Package.Match(newPackage)) throw new ArgumentException("The given directory is not contained in the given package.");

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                string previousDirectory = directory.Path;
                var result = UpdateUrl(newPackage, newDirectory, Name);
                UndoRedoService.SetName(transaction, $"Move asset '{Name}' from '{previousDirectory}' to '{newDirectory.Path}'");
                return result;
            }
        }

        [NotNull]
        public static HashSet<AssetViewModel> ComputeRecursiveReferencerAssets([NotNull] IEnumerable<AssetViewModel> assets)
        {
            var result = new HashSet<AssetViewModel>(assets.SelectMany(x => x.Dependencies.RecursiveReferencerAssets));
            return result;
        }

        [NotNull]

View on GitHub (pinned to 96fad776d2)