stride3d/stride · error · ArgumentException
Expecting an absolute directory
Error message
Expecting an absolute directory
What it means
UPath.MakeRelative throws ArgumentException when the anchorDirectory parameter is not an absolute directory. Making a path relative requires the anchor to be a fully-qualified absolute directory; passing a relative path or a file path cannot define a valid base.
Solutions
- Resolve the anchor to an absolute path (combine with the project/mount root) before calling MakeRelative
- Ensure the anchor is a UDirectory, not a UFile
- Check anchorDirectory.IsAbsolute before calling
Example fix
// before
var rel = filePath.MakeRelative(new UDirectory("assets")); // throws: not absolute
// after
var anchor = new UDirectory(Path.Combine(projectRoot, "assets"));
var rel = filePath.MakeRelative(anchor); Defensive patterns
Strategy: validation
Validate before calling
if (!anchorDirectory.IsAbsolute)
anchorDirectory = new UDirectory(Path.Combine(rootPath, anchorDirectory.ToString()));
var rel = filePath.MakeRelative(anchorDirectory); Prevention
- Resolve configured base directories to absolute paths at startup
- Ensure the anchor is a UDirectory, never a UFile
When it happens
Trigger: Calling path.MakeRelative(relativeOrNonAbsolutePath) where the anchor is relative (e.g. "assets/textures" without root), or a UFile rather than a UDirectory.
Common situations: Building paths from user/project config where the base directory is stored as a relative path, forgetting to resolve the anchor against the project root first.
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
- A file path cannot end with with directory char '\' or '/'…
- Path should have no drive information/or both drive…
- Operation 'Read' is not supported
- Operation 'Write' is not supported
- The provided path is not a valid path name.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/0d83f3dcaffec2fe.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Design/IO/UPath.cs:360
/// <returns>A relative path of this instance to the anchor directory.</returns>
public UPath MakeRelative(UDirectory anchorDirectory)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(anchorDirectory);
#else
if (anchorDirectory is null) throw new ArgumentNullException(nameof(anchorDirectory));
#endif
// If the toRelativize path is already relative, don't bother
if (IsRelative)
{
return this;
}
// If anchor directory is not absolute directory, throw an error
if (!anchorDirectory.IsAbsolute)
{
throw new ArgumentException("Expecting an absolute directory", nameof(anchorDirectory));
}
if (anchorDirectory.HasDrive != HasDrive)
{
throw new InvalidOperationException("Path should have no drive information/or both drive information simultaneously");
}
// Return a "." when the directory is the same
if (this is UDirectory && anchorDirectory == this)
{
return UDirectory.This;
}
// Get the full path of the anchor directory
var anchorPath = anchorDirectory.FullPath;
// Builds an absolute path for the toRelative path (directory-only)
var absoluteFile = Combine(anchorDirectory, this);View on GitHub (pinned to 96fad776d2)