{"record":{"id":"d19609cb08517be7","repo":"stride3d/stride","slug":"expecting-relative-path","errorCode":null,"errorMessage":"Expecting relative path","messagePattern":"Expecting relative path","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Package.cs","lineNumber":344,"sourceCode":"    /// <param name=\"pathToMsproj\">The path to msproj.</param>\n    /// <returns>LoggerResult.</returns>\n    public LoggerResult AddExistingProject(UFile pathToMsproj)\n    {\n        var logger = new LoggerResult();\n        AddExistingProject(pathToMsproj, logger);\n        return logger;\n    }\n\n    /// <summary>\n    /// Adds an existing project to this package.\n    /// </summary>\n    /// <param name=\"pathToMsproj\">The path to msproj.</param>\n    /// <param name=\"logger\">The logger.</param>\n    public void AddExistingProject(UFile pathToMsproj, LoggerResult logger)\n    {\n        ArgumentNullException.ThrowIfNull(pathToMsproj);\n        ArgumentNullException.ThrowIfNull(logger);\n        if (!pathToMsproj.IsAbsolute) throw new ArgumentException(\"Expecting relative path\", nameof(pathToMsproj));\n\n        try\n        {\n            // Load a project without specifying a platform to make sure we get the correct platform type\n            var msProject = VSProjectHelper.LoadProject(pathToMsproj, platform: \"NoPlatform\");\n            try\n            {\n                var projectType = VSProjectHelper.GetProjectTypeFromProject(msProject);\n                var platformType = VSProjectHelper.GetPlatformTypeFromProject(msProject) ?? PlatformType.Shared;\n                var projectReference = new ProjectReference(VSProjectHelper.GetProjectGuid(msProject), pathToMsproj.MakeRelative(RootDirectory), projectType);\n\n                // TODO CSPROJ=XKPKG\n                throw new NotImplementedException();\n                // Add the ProjectReference only for the compatible profiles (same platform or no platform)\n                //foreach (var profile in Profiles.Where(profile => platformType == profile.Platform))\n                //{\n                //    profile.ProjectReferences.Add(projectReference);\n                //}","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Package.cs#L326-L362","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npackage.AddExistingProject(new UFile(@\"C:\\dev\\MyGame\\MyGame.csproj\"), logger);\n// after\nvar abs = new UFile(@\"C:\\dev\\MyGame\\MyGame.csproj\");\nvar rel = new UFile(System.IO.Path.GetRelativePath(package.RootDirectory, abs));\npackage.AddExistingProject(rel, logger);","handlingStrategy":"validation","validationCode":"if (projPath.IsAbsolute) projPath = new UFile(Path.GetRelativePath(package.RootDirectory, projPath));","typeGuard":null,"tryCatchPattern":"try { package.AddExistingProject(rel, logger); } catch (ArgumentException ex) { log.Error(ex.Message); }","preventionTips":["Always store project references relative to the package root","Convert absolute browse-dialog results before calling","Normalize paths early in tooling code"],"tags":["path","argument","package"],"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"}