{"record":{"id":"6ba4b54de10643df","repo":"stride3d/stride","slug":"a-file-path-cannot-end-with-with-directory-char-or-or-a","errorCode":null,"errorMessage":"A file path cannot end with with directory char '\\' or '/', or a volume separator ':'.","messagePattern":"A file path cannot end with with directory char '\\\\' or '/', or a volume separator ':'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/IO/UPath.cs","lineNumber":62,"sourceCode":"    /// The directory separator string '/' used to separate directory in an url.\n    /// </summary>\n    public const string DirectorySeparatorString = \"/\";\n\n    /// <summary>\n    /// The directory separator string '\\' used to separate directory in an url.\n    /// </summary>\n    public const string DirectorySeparatorStringAlt = \"\\\\\";\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"UPath\" /> class from a file path.\n    /// </summary>\n    /// <param name=\"filePath\">The full path to a file.</param>\n    /// <param name=\"isDirectory\">if set to <c>true</c> the filePath is considered as a directory and not a filename.</param>\n    internal UPath(string? filePath, bool isDirectory)\n    {\n        if (!isDirectory && filePath != null && (filePath.EndsWith(DirectorySeparatorChar) || filePath.EndsWith(DirectorySeparatorCharAlt) || filePath.EndsWith(Path.VolumeSeparatorChar)))\n        {\n            throw new ArgumentException(\"A file path cannot end with with directory char '\\\\' or '/', or a volume separator ':'.\");\n        }\n\n        FullPath = Decode(filePath, isDirectory, out DriveSpan, out DirectorySpan, out NameSpan, out ExtensionSpan);\n        hashCode = ComputeStringHashCodeCaseInsensitive(FullPath);\n    }\n\n    protected UPath(string fullPath, StringSpan driveSpan, StringSpan directorySpan)\n    {\n#if NET6_0_OR_GREATER\n        ArgumentNullException.ThrowIfNull(fullPath);\n#else\n        if (fullPath is null) throw new ArgumentNullException(nameof(fullPath));\n#endif\n        FullPath = fullPath;\n        hashCode = ComputeStringHashCodeCaseInsensitive(fullPath);\n        DriveSpan = driveSpan;\n        DirectorySpan = directorySpan;\n    }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/IO/UPath.cs#L44-L80","documentation":"The internal UPath(string, bool) constructor throws ArgumentException when representing a FILE path whose string ends with a directory separator ('\\\\' or '/') or a volume separator (':'). A file path must point to a named file, so trailing separator characters make it ambiguous/invalid. Directory paths are exempt via the isDirectory flag.","triggerScenarios":"Constructing UPath for a file from a string like \"C:/dir/file/\" or \"/assets/model:\" — trailing '/' or ':' with isDirectory=false.","commonSituations":"String concatenation building paths and leaving a trailing slash, copy-pasting a directory path and treating it as a file, parsing user-supplied paths without trimming.","solutions":["Trim trailing separators from the string before constructing the UPath","Pass isDirectory:true if the path really denotes a directory","Use UDirectory/UFile typed helpers instead of raw string construction"],"exampleFix":"// before\nvar path = new UPath(\"assets/model/\", false); // throws\n// after\nvar path = new UPath(\"assets/model/\".TrimEnd('/', '\\\\'), false);","handlingStrategy":"validation","validationCode":"if (!isDirectory && filePath != null)\n    filePath = filePath.TrimEnd('/', '\\\\', ':');\nvar path = new UPath(filePath, isDirectory);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim trailing separators when building paths via string concatenation","Use UFile/UDirectory typed paths instead of raw strings","Validate user-supplied paths before conversion"],"tags":["csharp","io","paths"],"backgroundTag":"invalid-argument-format","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"}