stride3d/stride · error · ArgumentException
Invalid relative path. Expecting an absolute project path
Error message
Invalid relative path. Expecting an absolute project path
What it means
AddExistingProject requires an absolute path to the project file. Passing a relative UFile throws ArgumentException, because subsequent File.Exists and package loading logic depend on a fully qualified location.
Solutions
- Resolve to an absolute path with Path.GetFullPath (combined with your base directory) before calling
- Check projectPath.IsAbsolute before the call
- Build the path from an absolute root directory constant
Example fix
// before
session.AddExistingProject("src/MyGame.csproj", logger);
// after
var abs = new UFile(Path.GetFullPath("src/MyGame.csproj"));
session.AddExistingProject(abs, logger); Defensive patterns
Strategy: validation
Validate before calling
var abs = new UFile(Path.GetFullPath(projectPath));
if (!abs.IsAbsolute) throw new ArgumentException("Project path must be absolute", nameof(projectPath)); Type guard
bool IsAbsoluteProjectPath(UFile p) => p != null && p.IsAbsolute;
Try / catch
try { session.AddExistingProject(path, logger); }
catch (ArgumentException ex) { logger.Error(ex, "Project path must be absolute"); } Prevention
- Resolve config/CLI-supplied paths with Path.GetFullPath at the boundary
- Check UFile.IsAbsolute before calling path-based APIs
- Keep a single rooted base-directory constant for building paths
When it happens
Trigger: Calling session.AddExistingProject("MyGame/MyGame.csproj", logger) with a relative path, or a path built from the current directory implicitly.
Common situations: Taking a project path from command-line args or config without resolving it, hard-coded relative paths that worked by accident in another working directory.
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
- Expecting relative path
- filePath must be relative
- The value must be a non-null string when type is…
- The value must be null when type is ElementType.Target.
- The value must be an Index when type is ElementType.Index.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/67f367262acf3b85.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/PackageSession.cs:701
return sourceTracker ??= new AssetSourceTracker(this);
}
}
}
/// <summary>
/// Adds an existing package to the current session.
/// </summary>
/// <param name="projectPath">The project or package path.</param>
/// <param name="logger">The session result.</param>
/// <param name="loadParametersArg">The load parameters argument.</param>
/// <exception cref="ArgumentNullException">packagePath</exception>
/// <exception cref="ArgumentException">Invalid relative path. Expecting an absolute package path;packagePath</exception>
/// <exception cref="FileNotFoundException">Unable to find package</exception>
public PackageContainer AddExistingProject(UFile projectPath, ILogger logger, PackageLoadParameters? loadParametersArg = null)
{
ArgumentNullException.ThrowIfNull(projectPath);
ArgumentNullException.ThrowIfNull(logger);
if (!projectPath.IsAbsolute) throw new ArgumentException("Invalid relative path. Expecting an absolute project path", nameof(projectPath));
if (!File.Exists(projectPath)) throw new FileNotFoundException("Unable to find project", projectPath);
var loadParameters = loadParametersArg ?? PackageLoadParameters.Default();
Package package;
PackageContainer project;
try
{
// Enable reference analysis caching during loading
AssetReferenceAnalysis.EnableCaching = true;
project = LoadProject(logger, projectPath.ToOSPath(), loadParametersArg);
Projects.Add(project);
package = project.Package;
// Load all missing references/dependencies
LoadMissingDependencies(logger, loadParameters);View on GitHub (pinned to 96fad776d2)