{"record":{"id":"89ab0765d37f5b01","repo":"dotnet/wpf","slug":"sr-unsupportedattribute","errorCode":null,"errorMessage":"SR.UnsupportedAttribute","messagePattern":"SR\\.UnsupportedAttribute","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Text/TextRange.cs","lineNumber":180,"sourceCode":"        /// Searches for a subrange of text that has the specified attribute.\n        /// To search the entire document use the text pattern's document range.\n        /// </summary>\n        /// <param name=\"attribute\">The attribute to search for.</param>\n        /// <param name=\"value\">The value of the specified attribute to search for.  The value must be of the exact type specified for the \n        /// attribute.  For example when searching for font size you must specify the size in points as a double.\n        /// If you specify the point size as an integer then you will never get any matches due to the differing types.</param>\n        /// <param name=\"backward\">true if the last occurring range should be returned instead of the first.</param>\n        /// <returns>A subrange with the specified attribute, or null if no such subrange exists.</returns>\n        public TextPatternRange FindAttribute(AutomationTextAttribute attribute, object value, bool backward)\n        {\n            ArgumentNullException.ThrowIfNull(attribute);\n            ArgumentNullException.ThrowIfNull(value); // no text attributes can have null as a valid value\n\n            // Check that attribute value is of expected type...\n            AutomationAttributeInfo ai;\n            if(!Schema.GetAttributeInfo(attribute, out ai))\n            {\n                throw new ArgumentException(SR.UnsupportedAttribute);\n            }\n\n            if (value.GetType() != ai.Type)\n            {\n                throw new ArgumentException(SR.Format(SR.TextAttributeValueWrongType, attribute, ai.Type.Name, value.GetType().Name), nameof(value));\n            }\n\n            // note: if we implement attributes whose values are logical elements, patterns,\n            // or ranges then we'll need to unwrap the objects here before passing them on to\n            // the provider.\n            if (attribute == TextPattern.CultureAttribute)\n            {\n                if (value is CultureInfo)\n                {\n                    value = ((CultureInfo)value).LCID;\n                }\n            }\n","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/Text/TextRange.cs#L162-L198","documentation":"FindAttribute rejects the requested attribute because it is not registered in the UI Automation TextPattern attribute schema. Schema.GetAttributeInfo returned false, meaning the AutomationTextAttribute is unknown to the client-side TextPattern schema. The library throws ArgumentException because only attributes with an entry in the schema (including a known value type) can be queried.","triggerScenarios":"Calling TextPatternRange.FindAttribute with an AutomationTextAttribute that is not one of TextPattern's supported attributes (e.g. an attribute from a different pattern such as TablePattern or a custom provider attribute), or an attribute object fabricated/default-initialized rather than obtained from TextPattern's static fields.","commonSituations":"Developers generalize attribute-search code and pass attributes collected from other patterns; code written against a newer UIA spec attribute that the .NET WPF UIAutomationClient schema does not know; typos or reflection-produced attribute instances.","solutions":["Pass only attributes declared on TextPattern, e.g. TextPattern.BackgroundColorAttribute, TextPattern.FontNameAttribute, TextPattern.CultureAttribute.","Verify the attribute comes from the TextPattern class and not another pattern or a custom attribute.","If you need an attribute not in the schema, query it via the provider/UIA COM API directly instead of FindAttribute."],"exampleFix":"// before\nrange.FindAttribute(someOtherPattern.Attribute, value, false);\n// after\nrange.FindAttribute(TextPattern.FontNameAttribute, value, false);","handlingStrategy":"validation","validationCode":"private static readonly HashSet<AutomationTextAttribute> Supported = new() {\n    TextPattern.BackgroundColorAttribute, TextPattern.CultureAttribute,\n    TextPattern.FontNameAttribute, TextPattern.FontSizeAttribute,\n    TextPattern.FontWeightAttribute, TextPattern.ForegroundColorAttribute,\n    TextPattern.HorizontalTextAlignmentAttribute, TextPattern.IsItalicAttribute,\n    TextPattern.IsReadOnlyAttribute, TextPattern.IsSubscriptAttribute,\n    TextPattern.IsSuperscriptAttribute, TextPattern.UnderlineStyleAttribute,\n    TextPattern.AnnotationTypesAttribute, TextPattern.AnnotationObjectsAttribute,\n    TextPattern.StyleNameAttribute, TextPattern.TextFlowDirectionsAttribute };\nif (!Supported.Contains(attribute)) throw new NotSupportedException($\"Attribute {attribute} not supported by TextPattern.\");","typeGuard":"static bool IsTextPatternAttribute(AutomationTextAttribute a) =>\n    a == TextPattern.BackgroundColorAttribute || a == TextPattern.CultureAttribute ||\n    a == TextPattern.FontNameAttribute || a == TextPattern.FontSizeAttribute || /* ...full whitelist... */\n    a == TextPattern.UnderlineStyleAttribute;","tryCatchPattern":"try { range.FindAttribute(attribute, value, false); }\ncatch (ArgumentException) { log.Warn($\"Unsupported text attribute: {attribute.ProgrammaticName}\"); }","preventionTips":["Only pass static fields from the TextPattern class as attributes","Never share attribute objects across different UIA patterns","Centralize supported-attribute whitelists in test helpers"],"tags":["uiautomation","textpattern","argument-exception","unsupported-attribute"],"backgroundTag":"unsupported-operation","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"}