stride3d/stride · error · ArgumentException
Extension contains invalid characters
Error message
Extension contains invalid characters
What it means
FileExtensionCollection.NormalizeExtension rejects extension strings containing characters that are invalid in file names (per Path.GetInvalidFileNameChars), other than '*'. This guards the collection against malformed extensions that could never match a real file.
Solutions
- Strip invalid characters or pass only the extension portion (e.g. ".png")
- Extract the extension with Path.GetExtension before adding
- Sanitize user/config-supplied extension strings before registering them
Example fix
// before
collection.Add(Path.GetFileName("C:/icons/logo.png"));
// after
collection.Add(Path.GetExtension("C:/icons/logo.png")); Defensive patterns
Strategy: validation
Validate before calling
if (ext.Any(c => c != '*' && Path.GetInvalidFileNameChars().Contains(c))) throw new ArgumentException("Invalid chars in extension", nameof(ext)); Try / catch
try { collection.Add(ext); } catch (ArgumentException) { collection.Add(Path.GetExtension(ext)); } Prevention
- Pass Path.GetExtension output, not file names or paths
- Sanitize config/user input for extensions
- Test extensions against Path.GetInvalidFileNameChars
When it happens
Trigger: Adding an extension containing characters like '\\', '/', ':', quotes, or other invalid filename characters, e.g. collection.Add("*.pn|g") or an extension pasted from a full path.
Common situations: Accidentally passing a full file path instead of an extension; typos or shell-escaped characters in configuration; Windows-invalid characters on cross-platform inputs.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Expecting a single extension
- 's must be finite and greater than zero
- Value must be > 0
- This method must be invoked with at least one property name.
- Cannot use as a list of digit
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/42a83fca0dbe93fe.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/IO/FileExtensionCollection.cs:90
private static List<string> SplitExtensions(string extensions)
{
return extensions.Split([';', ','], StringSplitOptions.RemoveEmptyEntries).Select(NormalizeExtension).ToList();
}
private static string NormalizeExtension(string extension)
{
ArgumentNullException.ThrowIfNull(extension);
if (extension.Contains(';') || extension.Contains(','))
throw new ArgumentException("Expecting a single extension");
if (extension.StartsWith("*.", StringComparison.Ordinal))
{
extension = extension[1..];
}
if (extension.Any(x => x != '*' & Path.GetInvalidFileNameChars().Contains(x)))
throw new ArgumentException("Extension contains invalid characters");
if (!extension.StartsWith('.'))
{
extension = $".{extension}";
}
return extension.ToLowerInvariant();
}
}
View on GitHub (pinned to 96fad776d2)