{"record":{"id":"3eb1f946551d08f4","repo":"dotnet/wpf","slug":"name","errorCode":null,"errorMessage":"name","messagePattern":"name","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEditRange.cs","lineNumber":1261,"sourceCode":"            {\n                case TextUnit.Character:\n                    return TomUnit.tomCharacter;\n\n                case TextUnit.Word:\n                    return TomUnit.tomWord;\n\n                case TextUnit.Line:\n                    return TomUnit.tomLine;\n\n                case TextUnit.Paragraph:\n                    return TomUnit.tomParagraph;\n\n                case TextUnit.Page:\n                case TextUnit.Document:\n                    return TomUnit.tomStory;\n\n                default:\n                    throw new ArgumentException(name);\n            }\n        }\n\n        #endregion Private Methods\n\n        //------------------------------------------------------\n        //\n        //  Static Methods\n        //\n        //------------------------------------------------------\n\n        #region Static Methods\n\n        // these helper functions make it convenient to walk through a range by unit as follows:\n        //   int end = range.End;\n        //   for (ITextRange subrange=FirstUnit(range); NextUnit(end, subrange, tomUnit.tomCharFormat);)...\n        // and\n        //   int start = range.Start;","sourceCodeStart":1243,"sourceCodeEnd":1279,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsRichEditRange.cs#L1243-L1279","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nobject v = textRange.GetAttributeValue(TextPattern.ZoomAttribute);\n// after\nobject v;\ntry { v = textRange.GetAttributeValue(attr); }\ncatch (ArgumentException) { v = TextPattern.MixedAttributeValue; /* unsupported */ }","handlingStrategy":"try-catch","validationCode":"bool isSupported = TextUnit.Character <= unit && unit <= TextUnit.Document; // RichEdit proxy supports these only","typeGuard":"static bool IsSupportedTextUnit(TextUnit u) => u >= TextUnit.Character && u <= TextUnit.Document;","tryCatchPattern":"try { value = range.GetAttributeValue(unit); }\ncatch (ArgumentException) { value = AutomationElement.NotSupported; /* unsupported unit */ }","preventionTips":["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"],"tags":["uiautomation","argument-exception","wpf","textunit"],"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"}