{"record":{"id":"42a83fca0dbe93fe","repo":"stride3d/stride","slug":"extension-contains-invalid-characters","errorCode":null,"errorMessage":"Extension contains invalid characters","messagePattern":"Extension contains invalid characters","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/IO/FileExtensionCollection.cs","lineNumber":90,"sourceCode":"\n    private static List<string> SplitExtensions(string extensions)\n    {\n        return extensions.Split([';', ','], StringSplitOptions.RemoveEmptyEntries).Select(NormalizeExtension).ToList();\n    }\n\n    private static string NormalizeExtension(string extension)\n    {\n        ArgumentNullException.ThrowIfNull(extension);\n\n        if (extension.Contains(';') || extension.Contains(','))\n            throw new ArgumentException(\"Expecting a single extension\");\n\n        if (extension.StartsWith(\"*.\", StringComparison.Ordinal))\n        {\n            extension = extension[1..];\n        }\n        if (extension.Any(x => x != '*' & Path.GetInvalidFileNameChars().Contains(x)))\n            throw new ArgumentException(\"Extension contains invalid characters\");\n\n        if (!extension.StartsWith('.'))\n        {\n            extension = $\".{extension}\";\n        }\n        return extension.ToLowerInvariant();\n    }\n}\n","sourceCodeStart":72,"sourceCodeEnd":99,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/IO/FileExtensionCollection.cs#L72-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"Accidentally passing a full file path instead of an extension; typos or shell-escaped characters in configuration; Windows-invalid characters on cross-platform inputs.","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"],"exampleFix":"// before\ncollection.Add(Path.GetFileName(\"C:/icons/logo.png\"));\n// after\ncollection.Add(Path.GetExtension(\"C:/icons/logo.png\"));","handlingStrategy":"validation","validationCode":"if (ext.Any(c => c != '*' && Path.GetInvalidFileNameChars().Contains(c))) throw new ArgumentException(\"Invalid chars in extension\", nameof(ext));","typeGuard":null,"tryCatchPattern":"try { collection.Add(ext); } catch (ArgumentException) { collection.Add(Path.GetExtension(ext)); }","preventionTips":["Pass Path.GetExtension output, not file names or paths","Sanitize config/user input for extensions","Test extensions against Path.GetInvalidFileNameChars"],"tags":["validation","file-extension","argument"],"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"}