stride3d/stride · error · ArgumentException
Expecting relative path
Error message
Expecting relative path
What it means
Package.AddExistingProject requires pathToMsproj to be a relative path (UFile.IsAbsolute must be false). Passing an absolute path throws ArgumentException because the package stores project references relative to its own location.
Solutions
- Convert the path to relative form with respect to the package directory before calling
- Use UFile's relative-path helpers (e.g. Path.GetRelativePath against the package root)
- Change the calling tool to store/emit relative project references
Example fix
// before package.AddExistingProject(new UFile(@"C:\dev\MyGame\MyGame.csproj"), logger); // after var abs = new UFile(@"C:\dev\MyGame\MyGame.csproj"); var rel = new UFile(System.IO.Path.GetRelativePath(package.RootDirectory, abs)); package.AddExistingProject(rel, logger);
Defensive patterns
Strategy: validation
Validate before calling
if (projPath.IsAbsolute) projPath = new UFile(Path.GetRelativePath(package.RootDirectory, projPath));
Try / catch
try { package.AddExistingProject(rel, logger); } catch (ArgumentException ex) { log.Error(ex.Message); } Prevention
- Always store project references relative to the package root
- Convert absolute browse-dialog results before calling
- Normalize paths early in tooling code
When it happens
Trigger: Calling AddExistingProject with an absolute path such as "C:\\proj\\My.csproj" or "/home/u/proj/My.csproj" instead of a path relative to the package root.
Common situations: Browsing for a .csproj with an absolute file path from a tool/editor and passing it directly; path built from Environment.CurrentDirectory; migrating scripts written for absolute paths.
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
- filePath must be relative
- Invalid relative path. Expecting an absolute project path
- 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/d19609cb08517be7.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/Package.cs:344
/// <param name="pathToMsproj">The path to msproj.</param>
/// <returns>LoggerResult.</returns>
public LoggerResult AddExistingProject(UFile pathToMsproj)
{
var logger = new LoggerResult();
AddExistingProject(pathToMsproj, logger);
return logger;
}
/// <summary>
/// Adds an existing project to this package.
/// </summary>
/// <param name="pathToMsproj">The path to msproj.</param>
/// <param name="logger">The logger.</param>
public void AddExistingProject(UFile pathToMsproj, LoggerResult logger)
{
ArgumentNullException.ThrowIfNull(pathToMsproj);
ArgumentNullException.ThrowIfNull(logger);
if (!pathToMsproj.IsAbsolute) throw new ArgumentException("Expecting relative path", nameof(pathToMsproj));
try
{
// Load a project without specifying a platform to make sure we get the correct platform type
var msProject = VSProjectHelper.LoadProject(pathToMsproj, platform: "NoPlatform");
try
{
var projectType = VSProjectHelper.GetProjectTypeFromProject(msProject);
var platformType = VSProjectHelper.GetPlatformTypeFromProject(msProject) ?? PlatformType.Shared;
var projectReference = new ProjectReference(VSProjectHelper.GetProjectGuid(msProject), pathToMsproj.MakeRelative(RootDirectory), projectType);
// TODO CSPROJ=XKPKG
throw new NotImplementedException();
// Add the ProjectReference only for the compatible profiles (same platform or no platform)
//foreach (var profile in Profiles.Where(profile => platformType == profile.Platform))
//{
// profile.ProjectReferences.Add(projectReference);
//}View on GitHub (pinned to 96fad776d2)