{"record":{"id":"8ccd3178ac5bb14a","repo":"dotnet/wpf","slug":"sr-format-sr-enum-invalid-typeof-textmarkerstyle","errorCode":null,"errorMessage":"SR.Format(SR.Enum_Invalid, typeof(TextMarkerStyle))","messagePattern":"SR\\.Format\\(SR\\.Enum_Invalid, typeof\\(TextMarkerStyle\\)\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextSimpleMarkerProperties.cs","lineNumber":48,"sourceCode":"            ArgumentNullException.ThrowIfNull(textParagraphProperties);\n\n            _offset = offset;\n\n            if (style != TextMarkerStyle.None)\n            {\n                if (TextMarkerSource.IsKnownSymbolMarkerStyle(style))\n                {\n                    // autoNumberingIndex is ignored\n                }\n                else if (TextMarkerSource.IsKnownIndexMarkerStyle(style))\n                {\n                    // validate autoNumberingIndex\n                    ArgumentOutOfRangeException.ThrowIfNegativeOrZero(autoNumberingIndex);\n                }\n                else\n                {\n                    // invalid style\n                    throw new ArgumentException(SR.Format(SR.Enum_Invalid, typeof(TextMarkerStyle)), nameof(style));\n                }\n\n                _textSource = new TextMarkerSource(\n                    textParagraphProperties, \n                    style, \n                    autoNumberingIndex\n                    );\n            }\n        }\n\n\n        /// <summary>\n        /// Distance from line start to the end of the marker symbol\n        /// </summary>\n        public sealed override double Offset\n        {\n            get { return _offset; }\n        }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextSimpleMarkerProperties.cs#L30-L66","documentation":"The TextSimpleMarkerProperties constructor throws ArgumentException when the style parameter is not a valid TextMarkerStyle value. Only defined TextMarkerStyle members (None, Disc, Circle, Square, Box, LowerRoman, UpperRoman, LowerLatin, UpperLatin, Decimal, plus the arrow styles) are accepted; anything outside the enum's range is rejected. autoNumberingIndex must also be positive for auto-numbering styles.","triggerScenarios":"Casting an invalid int to TextMarkerStyle (e.g. (TextMarkerStyle)99) and passing it to TextSimpleMarkerProperties, or passing a garbage/uninitialized enum value from deserialization.","commonSituations":"Data binding or config that stores marker style as a raw int, deserialized legacy files with out-of-range values, typos when computing enum values.","solutions":["Validate the value with Enum.IsDefined(typeof(TextMarkerStyle), value) before constructing","Fix the source data/config so it contains only defined TextMarkerStyle members","Use TextMarkerStyle.None if no marker is desired instead of an out-of-range value"],"exampleFix":"// before\nvar marker = new TextSimpleMarkerProperties((TextMarkerStyle)42, 1, textSource);\n// after\nvar style = (TextMarkerStyle)42;\nif (!Enum.IsDefined(typeof(TextMarkerStyle), style)) style = TextMarkerStyle.None;\nvar marker = new TextSimpleMarkerProperties(style, 1, textSource);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(TextMarkerStyle), style)) throw new ArgumentException($\"Invalid TextMarkerStyle: {style}\");","typeGuard":"bool IsValidTextMarkerStyle(TextMarkerStyle s) => Enum.IsDefined(typeof(TextMarkerStyle), s);","tryCatchPattern":"try { new TextSimpleMarkerProperties(style, idx, src); } catch (ArgumentException) { style = TextMarkerStyle.None; }","preventionTips":["Never cast raw ints to TextMarkerStyle without Enum.IsDefined","Sanitize deserialized/config marker style values","Default to TextMarkerStyle.None for unknown values"],"tags":["wpf","textformatting","enum","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}