dotnet/wpf · error · ArgumentException
name
Error message
name
What it means
WindowsRichEditRange.GetAttributeValue throws ArgumentException when asked for a TextAttribute value with an unsupported TextUnit. The proxy only maps a known set of TextUnit units (Character, Format, Word, Line, Paragraph, Page, Document) to TOM units; anything else (e.g. TextUnit.Zoom, future enum values) falls through the switch's default case and the unit name itself is thrown as the message.
Solutions
- Restrict TextUnit arguments to TextUnit.Character through TextUnit.Document when working with RichEdit providers.
- Wrap GetAttributeValue in a try/catch for ArgumentException and treat it as 'unsupported attribute' rather than a fatal error.
- Update to a newer .NET/WPF servicing release that may support the requested TextUnit.
Example fix
// before
object v = textRange.GetAttributeValue(TextPattern.ZoomAttribute);
// after
object v;
try { v = textRange.GetAttributeValue(attr); }
catch (ArgumentException) { v = TextPattern.MixedAttributeValue; /* unsupported */ } Defensive patterns
Strategy: try-catch
Validate before calling
bool isSupported = TextUnit.Character <= unit && unit <= TextUnit.Document; // RichEdit proxy supports these only
Type guard
static bool IsSupportedTextUnit(TextUnit u) => u >= TextUnit.Character && u <= TextUnit.Document;
Try / catch
try { value = range.GetAttributeValue(unit); }
catch (ArgumentException) { value = AutomationElement.NotSupported; /* unsupported unit */ } Prevention
- Restrict TextUnit values to Character..Document for RichEdit targets
- Treat ArgumentException from GetAttributeValue as 'attribute not supported'
- Probe attributes once per control type and cache support results
When it happens
Trigger: Calling TextRange.GetAttributeValue with an attribute that requires a TextUnit the RichEdit provider does not support, causing the switch in the TextUnit-to-TomUnit conversion helper to hit the default branch at WindowsRichEditRange.cs:1261.
Common situations: Automating legacy RichEdit controls via UIAutomation while requesting attributes across all TextUnit values; code written against a newer TextUnit enum (e.g. Zoom) that this WPF UIAutomation provider predates.
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
- E_INVALIDARG
- ArgumentOutOfRangeException (timeout was Duration.Automatic)
- Collection_BadRank
- Collection_CopyTo_ArrayCannotBeMultidimensional
- Collection_CopyTo_ArrayCannotBeMultidimensional
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3eb1f946551d08f4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEditRange.cs:1261
{
case TextUnit.Character:
return TomUnit.tomCharacter;
case TextUnit.Word:
return TomUnit.tomWord;
case TextUnit.Line:
return TomUnit.tomLine;
case TextUnit.Paragraph:
return TomUnit.tomParagraph;
case TextUnit.Page:
case TextUnit.Document:
return TomUnit.tomStory;
default:
throw new ArgumentException(name);
}
}
#endregion Private Methods
//------------------------------------------------------
//
// Static Methods
//
//------------------------------------------------------
#region Static Methods
// these helper functions make it convenient to walk through a range by unit as follows:
// int end = range.End;
// for (ITextRange subrange=FirstUnit(range); NextUnit(end, subrange, tomUnit.tomCharFormat);)...
// and
// int start = range.Start;View on GitHub (pinned to 81131a70a4)