{"record":{"id":"0d83f3dcaffec2fe","repo":"stride3d/stride","slug":"expecting-an-absolute-directory","errorCode":null,"errorMessage":"Expecting an absolute directory","messagePattern":"Expecting an absolute directory","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/IO/UPath.cs","lineNumber":360,"sourceCode":"    /// <returns>A relative path of this instance to the anchor directory.</returns>\n    public UPath MakeRelative(UDirectory anchorDirectory)\n    {\n#if NET6_0_OR_GREATER\n        ArgumentNullException.ThrowIfNull(anchorDirectory);\n#else\n        if (anchorDirectory is null) throw new ArgumentNullException(nameof(anchorDirectory));\n#endif\n\n        // If the toRelativize path is already relative, don't bother\n        if (IsRelative)\n        {\n            return this;\n        }\n\n        // If anchor directory is not absolute directory, throw an error\n        if (!anchorDirectory.IsAbsolute)\n        {\n            throw new ArgumentException(\"Expecting an absolute directory\", nameof(anchorDirectory));\n        }\n\n        if (anchorDirectory.HasDrive != HasDrive)\n        {\n            throw new InvalidOperationException(\"Path should have no drive information/or both drive information simultaneously\");\n        }\n\n        // Return a \".\" when the directory is the same\n        if (this is UDirectory && anchorDirectory == this)\n        {\n            return UDirectory.This;\n        }\n\n        // Get the full path of the anchor directory\n        var anchorPath = anchorDirectory.FullPath;\n\n        // Builds an absolute path for the toRelative path (directory-only)\n        var absoluteFile = Combine(anchorDirectory, this);","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/IO/UPath.cs#L342-L378","documentation":"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.","triggerScenarios":"Calling path.MakeRelative(relativeOrNonAbsolutePath) where the anchor is relative (e.g. \"assets/textures\" without root), or a UFile rather than a UDirectory.","commonSituations":"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.","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"],"exampleFix":"// before\nvar rel = filePath.MakeRelative(new UDirectory(\"assets\")); // throws: not absolute\n// after\nvar anchor = new UDirectory(Path.Combine(projectRoot, \"assets\"));\nvar rel = filePath.MakeRelative(anchor);","handlingStrategy":"validation","validationCode":"if (!anchorDirectory.IsAbsolute)\n    anchorDirectory = new UDirectory(Path.Combine(rootPath, anchorDirectory.ToString()));\nvar rel = filePath.MakeRelative(anchorDirectory);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve configured base directories to absolute paths at startup","Ensure the anchor is a UDirectory, never a UFile"],"tags":["csharp","io","paths"],"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"}