{"record":{"id":"a2322e96b083d376","repo":"stride3d/stride","slug":"asset-location-0-cannot-contain-drive-information","errorCode":null,"errorMessage":"Asset location [{0}] cannot contain drive information","messagePattern":"Asset location \\[(.+?)\\] cannot contain drive information","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/PackageAssetCollection.cs","lineNumber":365,"sourceCode":"            else if (location.IsAbsolute)\n            {\n                throw new ArgumentException(\"Asset location [{0}] must be relative and not absolute (not start with '/')\".ToFormat(location), nameof(item));\n            }\n        }\n\n        if (referenceable && mapPathToId.ContainsKey(location))\n        {\n            throw new ArgumentException(\"An asset [{0}] with the same location [{1}] is already registered \".ToFormat(mapPathToId[location], location.GetDirectoryAndFileName()), nameof(item));\n        }\n\n        if (mapIdToPath.ContainsKey(item.Id))\n        {\n            throw new ArgumentException(\"An asset with the same id [{0}] is already registered with the location [{1}]\".ToFormat(item.Id, location.GetDirectoryAndFileName()), nameof(item));\n        }\n\n        if (location.HasDrive)\n        {\n            throw new ArgumentException(\"Asset location [{0}] cannot contain drive information\".ToFormat(location), nameof(item));\n        }\n\n        if (location.GetDirectory()?.StartsWith(\"..\", StringComparison.Ordinal) == true)\n        {\n            throw new ArgumentException(\"Asset location [{0}] cannot start with relative '..'\".ToFormat(location), nameof(item));\n        }\n\n        // Double check that this asset is not already stored in another package for this session\n        if (Package.Session != null)\n        {\n            foreach (var otherPackage in Package.Session.Packages)\n            {\n                if (otherPackage != Package)\n                {\n                    if (otherPackage.Assets.ContainsById(item.Id))\n                    {\n                        throw new ArgumentException(\"Cannot add the asset [{0}] [{1}] to package [{2}] [{3}]: it is already in package [{4}] [{5}] in the current session\".ToFormat(item.Id, item.Location, Package.Meta.Name, Package.FullPath, otherPackage.Meta.Name, otherPackage.FullPath));\n                    }","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/PackageAssetCollection.cs#L347-L383","documentation":"Asset locations live in the package's virtual location space and must never carry OS drive information (e.g. 'C:\\'). CheckCanAdd rejects locations where UFile.HasDrive is true, because drive letters would leak filesystem-specific paths into serialized references and break cross-machine portability.","triggerScenarios":"Calling package.Assets.Add(item) with a location derived from an absolute filesystem path such as 'C:/Projects/Game/Assets/sword' instead of a package-relative virtual path.","commonSituations":"Passing full disk paths (from file pickers, Environment.CurrentDirectory concatenation, or import tooling) directly as the asset location instead of computing the path relative to the package root.","solutions":["Convert the absolute path to a package-relative virtual location before creating the AssetItem (e.g. use package.Container or UFile.MakeRelative against the package root directory).","Strip the drive component and rebuild the location from the package root folder onward.","Never build AssetItem locations from absolute paths — store and pass relative virtual paths only.","Validate with !location.HasDrive before Add."],"exampleFix":"// before\nvar item = new AssetItem(new UFile(@\"C:\\Dev\\MyGame\\Assets\\sword\"), asset);\npackage.Assets.Add(item); // throws: drive information\n\n// after\nvar relative = new UFile(@\"Assets\\sword\");\npackage.Assets.Add(new AssetItem(relative, asset));","handlingStrategy":"validation","validationCode":"if (item.Location.HasDrive)\n    item.Location = new UFile(item.Location.FullPath[(item.Location.FullPath.IndexOf('/', 1) + 1)..]);\npackage.Assets.Add(item);","typeGuard":"bool HasNoDrive(UFile loc) => !loc.HasDrive;","tryCatchPattern":"try { package.Assets.Add(item); }\ncatch (ArgumentException e) when (e.Message.Contains(\"drive information\"))\n{ /* convert to package-relative path and retry */ }","preventionTips":["Never build locations from absolute disk paths","Compute relative paths against the package root at import time","Test tools on both Windows (drive letters) and Unix"],"tags":["assets","paths","portability","argument-exception"],"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"}