stride3d/stride · error · ArgumentException
A file path cannot end with with directory char '\' or '/'…
Error message
A file path cannot end with with directory char '\' or '/', or a volume separator ':'.
What it means
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.
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
Example fix
// before
var path = new UPath("assets/model/", false); // throws
// after
var path = new UPath("assets/model/".TrimEnd('/', '\\'), false); Defensive patterns
Strategy: validation
Validate before calling
if (!isDirectory && filePath != null)
filePath = filePath.TrimEnd('/', '\\', ':');
var path = new UPath(filePath, isDirectory); Prevention
- Trim trailing separators when building paths via string concatenation
- Use UFile/UDirectory typed paths instead of raw strings
- Validate user-supplied paths before conversion
When it happens
Trigger: Constructing UPath for a file from a string like "C:/dir/file/" or "/assets/model:" — trailing '/' or ':' with isDirectory=false.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Expecting an absolute directory
- Path should have no drive information/or both drive…
- Operation 'Read' is not supported
- Operation 'Write' is not supported
- The provided path is not a valid path name.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/6ba4b54de10643df.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Design/IO/UPath.cs:62
/// The directory separator string '/' used to separate directory in an url.
/// </summary>
public const string DirectorySeparatorString = "/";
/// <summary>
/// The directory separator string '\' used to separate directory in an url.
/// </summary>
public const string DirectorySeparatorStringAlt = "\\";
/// <summary>
/// Initializes a new instance of the <see cref="UPath" /> class from a file path.
/// </summary>
/// <param name="filePath">The full path to a file.</param>
/// <param name="isDirectory">if set to <c>true</c> the filePath is considered as a directory and not a filename.</param>
internal UPath(string? filePath, bool isDirectory)
{
if (!isDirectory && filePath != null && (filePath.EndsWith(DirectorySeparatorChar) || filePath.EndsWith(DirectorySeparatorCharAlt) || filePath.EndsWith(Path.VolumeSeparatorChar)))
{
throw new ArgumentException("A file path cannot end with with directory char '\\' or '/', or a volume separator ':'.");
}
FullPath = Decode(filePath, isDirectory, out DriveSpan, out DirectorySpan, out NameSpan, out ExtensionSpan);
hashCode = ComputeStringHashCodeCaseInsensitive(FullPath);
}
protected UPath(string fullPath, StringSpan driveSpan, StringSpan directorySpan)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(fullPath);
#else
if (fullPath is null) throw new ArgumentNullException(nameof(fullPath));
#endif
FullPath = fullPath;
hashCode = ComputeStringHashCodeCaseInsensitive(fullPath);
DriveSpan = driveSpan;
DirectorySpan = directorySpan;
}View on GitHub (pinned to 96fad776d2)