{"record":{"id":"8ec34d4b8815b16f","repo":"stride3d/stride","slug":"the-given-directory-is-not-contained-in-the-given-package","errorCode":null,"errorMessage":"The given directory is not contained in the given package.","messagePattern":"The given directory is not contained in the given package\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs","lineNumber":324,"sourceCode":"                UndoRedoService.SetName(transaction, $\"Reconcile {Url} with its archetypes\");\n            }\n        }\n\n        /// <inheritdoc/>\n        public override string ToString()\n        {\n            return $\"{{{GetType().Name}: {Url}}}\";\n        }\n\n        /// <summary>\n        /// Moves this asset in a different directory of a different project.\n        /// </summary>\n        /// <param name=\"newPackage\">The target project.</param>\n        /// <param name=\"newDirectory\">The view model of the target directory.</param>\n        /// <returns></returns>\n        public bool MoveAsset(Package newPackage, [NotNull] DirectoryBaseViewModel newDirectory)\n        {\n            if (!newDirectory.Package.Match(newPackage)) throw new ArgumentException(\"The given directory is not contained in the given package.\");\n\n            using (var transaction = UndoRedoService.CreateTransaction())\n            {\n                string previousDirectory = directory.Path;\n                var result = UpdateUrl(newPackage, newDirectory, Name);\n                UndoRedoService.SetName(transaction, $\"Move asset '{Name}' from '{previousDirectory}' to '{newDirectory.Path}'\");\n                return result;\n            }\n        }\n\n        [NotNull]\n        public static HashSet<AssetViewModel> ComputeRecursiveReferencerAssets([NotNull] IEnumerable<AssetViewModel> assets)\n        {\n            var result = new HashSet<AssetViewModel>(assets.SelectMany(x => x.Dependencies.RecursiveReferencerAssets));\n            return result;\n        }\n\n        [NotNull]","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs#L306-L342","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass a directory view model obtained from the same target package: newDirectory.Package.Match(newPackage) must be true.","Resolve the directory through the target package's view model rather than reusing one from another package.","Add a pre-check before the call and surface a clearer user-facing message on mismatch."],"exampleFix":"// before\nasset.MoveAsset(otherPackage, directoryFromSourcePackage);\n// after\nvar targetDir = otherPackage.Directories.First(d => d.Path == \"/target/path\");\nasset.MoveAsset(otherPackage, targetDir);","handlingStrategy":"validation","validationCode":"if (!newDirectory.Package.Match(newPackage)) throw new ArgumentException(\"Target directory does not belong to the target package\");\nasset.MoveAsset(newPackage, newDirectory);","typeGuard":"bool IsValidMoveTarget(Package p, DirectoryBaseViewModel d) => d != null && d.Package.Match(p);","tryCatchPattern":"try { asset.MoveAsset(newPackage, newDirectory); }\ncatch (ArgumentException ex) { logger.Error(ex, \"Directory/package mismatch in move target\"); }","preventionTips":["Resolve directory view models from the target package itself","In drag-drop, verify the drop target package equals the move target package","Never reuse directory view models across projects"],"tags":["assets","move-operation","package","argument-validation"],"backgroundTag":"invalid-argument-value","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"}