dotnet/wpf · error · ArgumentException
SR.Format(SR.Enum_Invalid, typeof(TextMarkerStyle))
Error message
SR.Format(SR.Enum_Invalid, typeof(TextMarkerStyle))
What it means
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.
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
Example fix
// before var marker = new TextSimpleMarkerProperties((TextMarkerStyle)42, 1, textSource); // after var style = (TextMarkerStyle)42; if (!Enum.IsDefined(typeof(TextMarkerStyle), style)) style = TextMarkerStyle.None; var marker = new TextSimpleMarkerProperties(style, 1, textSource);
Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(TextMarkerStyle), style)) throw new ArgumentException($"Invalid TextMarkerStyle: {style}"); Type guard
bool IsValidTextMarkerStyle(TextMarkerStyle s) => Enum.IsDefined(typeof(TextMarkerStyle), s);
Try / catch
try { new TextSimpleMarkerProperties(style, idx, src); } catch (ArgumentException) { style = TextMarkerStyle.None; } Prevention
- Never cast raw ints to TextMarkerStyle without Enum.IsDefined
- Sanitize deserialized/config marker style values
- Default to TextMarkerStyle.None for unknown values
When it happens
Trigger: Casting an invalid int to TextMarkerStyle (e.g. (TextMarkerStyle)99) and passing it to TextSimpleMarkerProperties, or passing a garbage/uninitialized enum value from deserialization.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ArgumentOutOfRangeException(authentication)
- ArgumentOutOfRangeException(userActivationMode)
- autoComplete
- captureMode
- CultureSource
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8ccd3178ac5bb14a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextSimpleMarkerProperties.cs:48
ArgumentNullException.ThrowIfNull(textParagraphProperties);
_offset = offset;
if (style != TextMarkerStyle.None)
{
if (TextMarkerSource.IsKnownSymbolMarkerStyle(style))
{
// autoNumberingIndex is ignored
}
else if (TextMarkerSource.IsKnownIndexMarkerStyle(style))
{
// validate autoNumberingIndex
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(autoNumberingIndex);
}
else
{
// invalid style
throw new ArgumentException(SR.Format(SR.Enum_Invalid, typeof(TextMarkerStyle)), nameof(style));
}
_textSource = new TextMarkerSource(
textParagraphProperties,
style,
autoNumberingIndex
);
}
}
/// <summary>
/// Distance from line start to the end of the marker symbol
/// </summary>
public sealed override double Offset
{
get { return _offset; }
}View on GitHub (pinned to 81131a70a4)