{"record":{"id":"243535b74ddf75f9","repo":"stride3d/stride","slug":"invalid-length-for-fourcc-0-must-be-be-4-characters-long","errorCode":null,"errorMessage":"Invalid length for FourCC(\"{0}\". Must be be 4 characters long ","messagePattern":"Invalid length for FourCC\\(\"(.+?)\"\\. Must be be 4 characters long ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/FourCC.cs","lineNumber":47,"sourceCode":"namespace Stride\n{\n    /// <summary>\n    /// A FourCC descriptor.\n    /// </summary>\n    [DataSerializer(typeof(FourCC.Serializer))]\n    [StructLayout(LayoutKind.Sequential, Size = 4)]\n    internal struct FourCC : IEquatable<FourCC>\n    {\n        private readonly uint value;\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"FourCC\" /> struct.\n        /// </summary>\n        /// <param name=\"fourCC\">The fourCC value as a string .</param>\n        public FourCC(string fourCC)\n        {\n            if (fourCC.Length != 4)\n                throw new ArgumentException(string.Format(System.Globalization.CultureInfo.InvariantCulture, \"Invalid length for FourCC(\\\"{0}\\\". Must be be 4 characters long \", fourCC), \"fourCC\");\n            this.value = ((uint)fourCC[3]) << 24 | ((uint)fourCC[2]) << 16 | ((uint)fourCC[1]) << 8 | ((uint)fourCC[0]);\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"FourCC\" /> struct.\n        /// </summary>\n        /// <param name=\"byte1\">The byte1.</param>\n        /// <param name=\"byte2\">The byte2.</param>\n        /// <param name=\"byte3\">The byte3.</param>\n        /// <param name=\"byte4\">The byte4.</param>\n        public FourCC(char byte1, char byte2, char byte3, char byte4)\n        {\n            this.value = ((uint)byte4) << 24 | ((uint)byte3) << 16 | ((uint)byte2) << 8 | ((uint)byte1);\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"FourCC\" /> struct.\n        /// </summary>","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/FourCC.cs#L29-L65","documentation":"Thrown by the FourCC(string) constructor when the input string is not exactly 4 characters. A FourCC is by definition a 4-byte code, so any other length is invalid. Note the message text itself has typos (missing closing paren, doubled 'be').","triggerScenarios":"new FourCC(\"DDS\") (3 chars), new FourCC(\"\") (empty), new FourCC(\"DXGI \") or any string whose .Length != 4, e.g. format names read from config or parsed from headers.","commonSituations":"Parsing format tags from files or user config where trailing whitespace or a truncated tag slips in; hardcoding a 3-letter mnemonic like \"DDS\" or \"PNG\" instead of the real 4-char code (\"DDS \", \"PNG\\0\"); string slicing off by one.","solutions":["Ensure the string is exactly 4 characters before constructing (pad with spaces or '\\0' as the format requires)","Check the intended code: e.g. DDS uses \"DDS \", use the canonical constant rather than typing it","Validate input from config/files with a length check and trim or reject invalid tags"],"exampleFix":"// before\nvar fourCC = new FourCC(formatTag); // \"DDS\"\n// after\nif (formatTag.Length != 4) formatTag = formatTag.PadRight(4, ' ');\nvar fourCC = new FourCC(formatTag); // \"DDS \"","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(fourCC) || fourCC.Length != 4)\n    throw new ArgumentException($\"FourCC must be exactly 4 chars, got '{fourCC}'\", nameof(fourCC));","typeGuard":"bool IsValidFourCC(string s) => !string.IsNullOrEmpty(s) && s.Length == 4;","tryCatchPattern":"FourCC fourCC;\ntry\n{\n    fourCC = new FourCC(tag);\n}\ncatch (ArgumentException ex)\n{\n    log.Error($\"Invalid FourCC tag '{tag}': must be exactly 4 characters\", ex);\n    throw new FormatException($\"Bad format tag '{tag}'\");\n}","preventionTips":["Use named constants (e.g. FourCC(\"DDS \")) instead of inline strings","Remember implicit padding: 'DDS' must be \"DDS \" with a trailing space","Validate tags parsed from files/config before constructing"],"tags":["graphics","argument-validation","fourcc"],"backgroundTag":"invalid-constructor-argument","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"}