{"record":{"id":"ff16ec1ef506d263","repo":"stride3d/stride","slug":"specified-argument-was-out-of-range-of-valid-values","errorCode":null,"errorMessage":"Specified argument was out of range of valid values. (Parameter 'measurementMethod')","messagePattern":"Specified argument was out of range of valid values\\. \\(Parameter 'measurementMethod'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs","lineNumber":330,"sourceCode":"                    GlyphTypeface glyphTypeface;\n                    if (TryGetGlyphTypeface(fontFamily, FontStyles.Normal, fontWeight, FontStretches.Normal, out glyphTypeface))\n                        return MeasureTextSize(glyphTypeface, fontSize, text);\n                    // Fallback to TextBlock measurement method\n                    goto case TextMeasurementMethod.TextBlock;\n\n                case TextMeasurementMethod.TextBlock:\n                    var textBlock = new TextBlock\n                    {\n                        FontFamily = fontFamily,\n                        FontSize = fontSize,\n                        FontWeight = fontWeight,\n                        Text = text,\n                    };\n                    textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));\n                    return new Size(textBlock.DesiredSize.Width, textBlock.DesiredSize.Height);\n\n                default:\n                    throw new ArgumentOutOfRangeException(nameof(measurementMethod));\n            }\n        }\n\n        /// <inheritdoc/>\n        public Size MeasureTexts(IList<string> texts, FontFamily fontFamily, double fontSize, FontWeight fontWeight, TextMeasurementMethod measurementMethod)\n        {\n            if (texts == null) throw new ArgumentNullException(nameof(texts));\n\n            var maxWidth = 0.0;\n            var maxHeight = 0.0;\n            TextBlock textBlock = null;\n            for (var i = 0; i < texts.Count; ++i)\n            {\n                var text = texts[i];\n                Size size;\n                switch (measurementMethod)\n                {\n                    case TextMeasurementMethod.GlyphTypeface:","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Drawing/CanvasRenderer.cs#L312-L348","documentation":"MeasureText selects a text measurement strategy via a TextMeasurementMethod enum. If the supplied value is not one of the defined enum members, the switch statement falls through to default and throws ArgumentOutOfRangeException. This typically happens with an invalid cast or a value from a newer/older assembly version.","triggerScenarios":"Calling MeasureText with an out-of-range TextMeasurementMethod, e.g. an unchecked cast like (TextMeasurementMethod)99 or an enum value from a different library version.","commonSituations":"Storing the method in config as an int and casting without validating; assembly version mismatch where the saved enum value no longer exists; copy-paste of a similarly named enum.","solutions":["Pass a valid TextMeasurementMethod enum member; validate config-sourced values with Enum.IsDefined before casting.","Replace unsafe int-to-enum casts with Enum.TryParse and a fallback default.","Check that all projects reference the same Stride assembly version."],"exampleFix":"// before\nvar method = (TextMeasurementMethod)settings.Method;\nvar size = renderer.MeasureText(text, font, size, weight, method);\n// after\nTextMeasurementMethod method = Enum.IsDefined(typeof(TextMeasurementMethod), settings.Method)\n    ? (TextMeasurementMethod)settings.Method\n    : TextMeasurementMethod.TextBlock;\nvar size = renderer.MeasureText(text, font, size, weight, method);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(TextMeasurementMethod), method)) method = TextMeasurementMethod.TextBlock;","typeGuard":"bool IsValidMethod(TextMeasurementMethod m) => Enum.IsDefined(typeof(TextMeasurementMethod), m);","tryCatchPattern":"try { size = renderer.MeasureText(text, font, fontSize, weight, method); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"measurementMethod\") { size = renderer.MeasureText(text, font, fontSize, weight, TextMeasurementMethod.TextBlock); }","preventionTips":["Never cast raw ints to enums without Enum.IsDefined","Use Enum.TryParse for config-sourced enum values","Keep Stride assembly versions consistent across projects"],"tags":["csharp","wpf","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}