{"record":{"id":"3dd0f741e596e77f","repo":"stride3d/stride","slug":"specified-argument-was-out-of-the-range-of-valid-values","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'stretchType')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'stretchType'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.UI/ImageSizeHelper.cs","lineNumber":66,"sourceCode":"            {\n                case StretchType.None:\n                    desiredScale = Vector2.One;\n                    break;\n                case StretchType.Uniform:\n                    desiredScale.X = desiredScale.Y = Math.Min(desiredScale.X, desiredScale.Y);\n                    break;\n                case StretchType.UniformToFill:\n                    desiredScale.X = desiredScale.Y = Math.Max(desiredScale.X, desiredScale.Y);\n                    break;\n                case StretchType.FillOnStretch:\n                    // if we are only measuring we prefer keeping the image resolution than using all the available space.\n                    if (isMeasuring)\n                        desiredScale.X = desiredScale.Y = Math.Min(desiredScale.X, desiredScale.Y);\n                    break;\n                case StretchType.Fill:\n                    break;\n                default:\n                    throw new ArgumentOutOfRangeException(nameof(stretchType));\n            }\n\n            // adjust the scales depending on the stretch directions\n            switch (stretchDirection)\n            {\n                case StretchDirection.Both:\n                    break;\n                case StretchDirection.DownOnly:\n                    desiredScale.X = Math.Min(desiredScale.X, 1);\n                    desiredScale.Y = Math.Min(desiredScale.Y, 1);\n                    break;\n                case StretchDirection.UpOnly:\n                    desiredScale.X = Math.Max(1, desiredScale.X);\n                    desiredScale.Y = Math.Max(1, desiredScale.Y);\n                    break;\n                default:\n                    throw new ArgumentOutOfRangeException(nameof(stretchDirection));\n            }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.UI/ImageSizeHelper.cs#L48-L84","documentation":"ImageSizeHelper.CalculateImageSizeFromAvailable switches on stretchType and its default branch throws ArgumentOutOfRangeException for any value outside the defined StretchType enum. This is an exhaustive-match guard protecting the scale computation.","triggerScenarios":"Passing a StretchType value not handled by the switch (e.g. an undefined enum cast like (StretchType)99), or an enum field defaulting to 0 when 0 is not a defined member in the current Stride version.","commonSituations":"Loading a StretchType from config/serialization where the numeric value is out of range; enum values changed between library versions; uninitialized struct fields defaulting to an unmapped value.","solutions":["Pass a valid StretchType: None, Uniform, UniformToFill, or Fill (as supported by your Stride version)","Validate/normalize the enum value before calling the helper and fall back to a known value","Fix deserialization so unknown values map to a default instead of being cast blindly"],"exampleFix":"// before\nvar size = ImageSizeHelper.CalculateImageSizeFromAvailable(avail, ideal, sprite, (StretchType)rawInt, dir);\n// after\nvar stretch = Enum.IsDefined(typeof(StretchType), rawInt) ? (StretchType)rawInt : StretchType.Uniform;\nvar size = ImageSizeHelper.CalculateImageSizeFromAvailable(avail, ideal, sprite, stretch, dir);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(StretchType), stretchType))\n    stretchType = StretchType.Uniform;","typeGuard":"static bool IsValidStretch(StretchType s) => s == StretchType.None || s == StretchType.Uniform || s == StretchType.UniformToFill || s == StretchType.Fill;","tryCatchPattern":"try { size = ImageSizeHelper.CalculateImageSizeFromAvailable(avail, ideal, sprite, stretch, dir); }\ncatch (ArgumentOutOfRangeException ex) { logger.LogWarning(\"Invalid {Param}, falling back to Uniform\", ex.ParamName); size = ImageSizeHelper.CalculateImageSizeFromAvailable(avail, ideal, sprite, StretchType.Uniform, dir); }","preventionTips":["Validate enum values from config/serialization with Enum.IsDefined","Never cast raw integers to enums without checking","Prefer switch-based mapping to a safe default value"],"tags":["csharp","ui","enum","argument-out-of-range"],"backgroundTag":"argument-out-of-range","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"}