stride3d/stride · error · ArgumentException
Asset location [ ] cannot contain drive information
Error message
Asset location [{0}] cannot contain drive information What it means
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.
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.
Example fix
// before var item = new AssetItem(new UFile(@"C:\Dev\MyGame\Assets\sword"), asset); package.Assets.Add(item); // throws: drive information // after var relative = new UFile(@"Assets\sword"); package.Assets.Add(new AssetItem(relative, asset));
Defensive patterns
Strategy: validation
Validate before calling
if (item.Location.HasDrive)
item.Location = new UFile(item.Location.FullPath[(item.Location.FullPath.IndexOf('/', 1) + 1)..]);
package.Assets.Add(item); Type guard
bool HasNoDrive(UFile loc) => !loc.HasDrive;
Try / catch
try { package.Assets.Add(item); }
catch (ArgumentException e) when (e.Message.Contains("drive information"))
{ /* convert to package-relative path and retry */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- Asset location [ ] must be relative and not absolute (not…
- Asset location [ ] cannot start with relative '..
- An IObjectNode was expected when processing the path
- An IMemberNode was expected when processing the path
- Cannot add an asset with an empty Id
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/a2322e96b083d376.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/PackageAssetCollection.cs:365
else if (location.IsAbsolute)
{
throw new ArgumentException("Asset location [{0}] must be relative and not absolute (not start with '/')".ToFormat(location), nameof(item));
}
}
if (referenceable && mapPathToId.ContainsKey(location))
{
throw new ArgumentException("An asset [{0}] with the same location [{1}] is already registered ".ToFormat(mapPathToId[location], location.GetDirectoryAndFileName()), nameof(item));
}
if (mapIdToPath.ContainsKey(item.Id))
{
throw new ArgumentException("An asset with the same id [{0}] is already registered with the location [{1}]".ToFormat(item.Id, location.GetDirectoryAndFileName()), nameof(item));
}
if (location.HasDrive)
{
throw new ArgumentException("Asset location [{0}] cannot contain drive information".ToFormat(location), nameof(item));
}
if (location.GetDirectory()?.StartsWith("..", StringComparison.Ordinal) == true)
{
throw new ArgumentException("Asset location [{0}] cannot start with relative '..'".ToFormat(location), nameof(item));
}
// Double check that this asset is not already stored in another package for this session
if (Package.Session != null)
{
foreach (var otherPackage in Package.Session.Packages)
{
if (otherPackage != Package)
{
if (otherPackage.Assets.ContainsById(item.Id))
{
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));
}View on GitHub (pinned to 96fad776d2)