{"record":{"id":"c9346c5136b1685c","repo":"stride3d/stride","slug":"path-should-have-no-drive-information-or-both-drive","errorCode":null,"errorMessage":"Path should have no drive information/or both drive information simultaneously","messagePattern":"Path should have no drive information/or both drive information simultaneously","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/IO/UPath.cs","lineNumber":365,"sourceCode":"#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);\n        var absolutePath = absoluteFile.GetFullDirectory().FullPath;\n\n        var relativePath = new StringBuilder();\n\n        var index = anchorPath.Length;","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/IO/UPath.cs#L347-L383","documentation":"UPath.MakeRelative throws InvalidOperationException when the path and its anchorDirectory disagree about drive information — one has a drive letter/URI scheme and the other does not. Paths with mixed drive-ness cannot be meaningfully related. This is a cross-domain consistency check after the absoluteness check.","triggerScenarios":"Calling MakeRelative where e.g. this = \"/assets/x\" (no drive) and anchor = \"C:/assets\" (has drive), or vice versa; also mixing scheme-less and scheme'd database paths.","commonSituations":"Combining paths from different sources (absolute Windows paths vs. virtual/mount-relative Stride paths), switching between file system paths and Stride's virtual file system URLs.","solutions":["Normalize both paths to the same drive/scheme domain before calling MakeRelative","Strip or add drive information consistently (e.g. use the mounted root path without drive)","Use the same path provider (VFS vs raw filesystem) for both paths"],"exampleFix":"// before\nvar rel = new UFile(\"C:/data/model.xk\").MakeRelative(new UDirectory(\"/data\")); // drive mismatch\n// after\nvar rel = new UFile(\"/data/model.xk\").MakeRelative(new UDirectory(\"/data\"));","handlingStrategy":"validation","validationCode":"if (path.HasDrive != anchorDirectory.HasDrive)\n    throw new InvalidOperationException(\"Path and anchor must agree on drive information.\");\nvar rel = path.MakeRelative(anchorDirectory);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use one path domain (VFS-style or drive-qualified) consistently across the codebase","Normalize paths to a common form before path algebra"],"tags":["csharp","io","paths"],"backgroundTag":"invalid-state-transition","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"}